![]() |
Stupid Javascript Question
Greetings earthlings,
I have a program that generates the URL of am image that looks like this http://something.jpg and it appears in the img code like this: <img src = "http://something.jpg"> What I need is a javascript that will insert a 1 into the file name so that the URL looks like this http://1something.jpg" so that the code looks like <img src = "<script>blahblah</script>"> STUPID question I know, but I just can't seem to figure this out. Any help gets you titties. thanks! |
Code:
let images = document.getElementsByTagName('img'); And don't put the script tags withing the img tag. It should be separate as it's own tag. |
no question is stupid question.
|
never mind what I said before.
|
It will never work
|
Hi ICebol,
Sorry but this didn't work for me. But I didn't include enough detail. Here's more: I have some HTML code that looks like this: *Start Loop* <img src="<!--Image-->"> *End Loop* Where the value of <!--image--> looks something like this: Code:
http://1.1.1.1/path/imagename.jpg Does that help? Or put another way: *Start Loop* *Load Image URL* *Javascript find character N and insert X after N* <img src = "use new URL to display image"> *end Loop* |
Quote:
|
Quote:
Now, what are you trying to accomplish, beyond what you have already said? What triggers this to happen? So, we have a page and when the page first comes up, there is an image. On some trigger (unknown at this time) you want the image name to be edited on the fly to another image (image). Am I on the right track? edited in: This code: so that the code looks like <img src = "<script>blahblah</script>"> Is not the way to implement anything. The only time that img tag is looked at would be at page load. aSince the script would be an invalid img ref it would just error out. The code that was posted in response would have to be run at the end of page load or when something triggered it (as I describe above). . |
Quote:
I will clarify: It is a loop because it is loading a bunch of pictures, one after another. The program doing it is outputting to HTML. Unfortunately I can't edit that program at the moment, so I'm looking to edit the HTML side instead. The string that the code generates looks like this: Code:
http://1.1.1.1/images/picture1.jpg But what I want to do is use some javascript to alter that string before placing it in the image tag. Does that make sense? Or am I losing my marbles? |
//get all images
//loop through all images src value //change src value to new value. //end. |
Quote:
|
Quote:
Code:
** Proudly accepting spare change at paypal to get account out of negative. :thumbsup |
Quote:
Ok, but that is different then what you said originally. How long do you want each image to appear for? What you are describing is basically a slideshow and there are many scripts available to do what you want. Again, what is the trigger? Do you just want it to loop through the whole time the page is being displayed, so from when the page loads to when the user leaves the page? Or is there some other trigger, user clicking something or anything like that? Quote:
. |
Demo at http://www.madspiders.com/imagetest.htm
Code used in the page: Code:
This is using a counter at the end of the base image name. You could have it insert into the imagename wherever you want it inserted. Since I don't know exactly where you want it inserted I just took the easy way out to show the concept. Is that kind of what you are trying to do? . |
Is this on the server side or client side? Are you using node.js?
|
Quote:
But he cannot edit the program so the images src has to be changed after the program put out the html; which means the images are already on the page (based on his statement) Javascript only executes on the html page DOM, so it's a given that the image src must already be part of the DOM. |
Quote:
Either way, he says he wants to modify the image url that the program is producing. I see nothing that says the image names are available in the dom. When/if Mark comes back he can clarify. What I got from it was he wanted to do a slideshow with the urls for the images being produced dynamically based on some formula that he has not revealed. This thread is a really good example of a piss poor project description. ;p imho. of course. . |
All times are GMT -7. The time now is 09:02 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123