![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,633
|
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!
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Industry Role:
Join Date: Oct 2017
Posts: 302
|
Code:
let images = document.getElementsByTagName('img'); for (i=0;i<images.length;i++){ let imageSrc = images[i].src.replace("http://","http://1"); images[i].src = imageSrc; } And don't put the script tags withing the img tag. It should be separate as it's own tag. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Jan 2012
Location: NC
Posts: 7,683
|
no question is stupid question.
__________________
SSD Cloud Server, VPS Server, Simple Cloud Hosting | DigitalOcean
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Jul 2012
Posts: 3,064
|
never mind what I said before.
__________________
Live Sex Shows |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
I need a beer
![]() Industry Role:
Join Date: Jun 2002
Location: ♠ Toiletville ♠
Posts: 133,928
|
It will never work
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,633
|
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*
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Too lazy to wipe my ass
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,531
|
Unless I am the one asking it...
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,060
|
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). .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,633
|
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?
__________________
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Industry Role:
Join Date: Jan 2012
Location: NC
Posts: 7,683
|
//get all images
//loop through all images src value //change src value to new value. //end.
__________________
SSD Cloud Server, VPS Server, Simple Cloud Hosting | DigitalOcean
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,633
|
Yes, almost. Change src value WITHIN the loop to new value. repeat, then end.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 | |
Making PHP work
Industry Role:
Join Date: Nov 2002
Location: 🌎🌅🌈🌇
Posts: 20,240
|
Quote:
Code:
<script> document.addEventListener("DOMContentLoaded", function(event) { var imgs = document.getElementsByTagName("img"); var ctr = imgs.length; var i; for (i = 0; i < ctr; i++) { hold = imgs[i].src; imgs[i].src = hold.replace("https://","https://1"); } }); </script> ** Proudly accepting spare change at paypal to get account out of negative. ![]()
__________________
Make Money with Porn |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 | ||
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,060
|
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:
.
__________________
All cookies cleared! |
||
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,060
|
Demo at http://www.madspiders.com/imagetest.htm
Code used in the page: Code:
<script type="text/javascript"> var imagecnt=1; var maximage=9; var timeout=1000; var imagename='testimages/carli_banks_1_000'; var imageid='myimageid'; function startit() { var run=window.setInterval(changeimage,timeout); } function changeimage() { imagecnt++;; if(imagecnt>1) { document.getElementById(imageid).src=imagename + imagecnt.toString() + '.jpg'; } if(imagecnt>=maximage) { imagecnt=1; } } </script> </head> <body> <img src="testimages/carli_banks_1_0001.jpg" id="myimageid" onClick="changeimage();" style="max-width:600;max-height:600;"> <br> <script> startit(); </script> </body> 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? .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
Confirmed User
Industry Role:
Join Date: Oct 2017
Posts: 302
|
Is this on the server side or client side? Are you using node.js?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 | |
Making PHP work
Industry Role:
Join Date: Nov 2002
Location: 🌎🌅🌈🌇
Posts: 20,240
|
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.
__________________
Make Money with Porn |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,060
|
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 cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() ![]() |
|||||||
|
|||||||
Bookmarks |
Tags |
url, stupid, code, javascript, question, http://1something.jpg, file, titties, figure, insert, earthlings, http://something.jpg, image, program, generates, appears, img |