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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 09-27-2018, 06:55 PM   #1
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
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!
__________________

Custom Software | Server Management | Integration and Technology Solutions
https://www.2much.net
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2018, 07:50 PM   #2
iceboi
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;
}
This code will modify all the images on the page. If you only want to modify 1 image, give the image an id and change "getElementsByTagName" to "getElementById" and replace "img" with the id of the image.

And don't put the script tags withing the img tag. It should be separate as it's own tag.
iceboi is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2018, 08:02 PM   #3
freecartoonporn
Confirmed User
 
freecartoonporn's Avatar
 
Industry Role:
Join Date: Jan 2012
Location: NC
Posts: 7,683
no question is stupid question.
freecartoonporn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2018, 10:49 PM   #4
lezinterracial
Confirmed User
 
Industry Role:
Join Date: Jul 2012
Posts: 3,064
never mind what I said before.
__________________
Live Sex Shows
lezinterracial is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2018, 10:58 PM   #5
Spunky
I need a beer
 
Spunky's Avatar
 
Industry Role:
Join Date: Jun 2002
Location: ♠ Toiletville ♠
Posts: 133,928
It will never work
__________________
Spunky is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-28-2018, 12:42 PM   #6
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
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
So what I want to do is have a javascript that runs within this loop, and inserts a character at a specific spot of that URL.

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*
__________________

Custom Software | Server Management | Integration and Technology Solutions
https://www.2much.net
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-28-2018, 12:59 PM   #7
CurrentlySober
Too lazy to wipe my ass
 
CurrentlySober's Avatar
 
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,531
Quote:
Originally Posted by freecartoonporn View Post
no question is stupid question.
Unless I am the one asking it...
__________________


👁️ 👍️ 💩
CurrentlySober is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-28-2018, 01:41 PM   #8
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,060
Quote:
Originally Posted by 2MuchMark View Post

*Start Loop*
*Load Image URL*
*Javascript find character N and insert X after N*
<img src = "use new URL to display image">
*end Loop*
That is not a loop. That is a straight line. A loop repeats.

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!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2018, 08:57 AM   #9
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,633
Quote:
Originally Posted by sarettah View Post
That is not a loop. That is a straight line. A loop repeats.

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).


.
Hi Sarah,

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
And if I place that string in an IMG tag it loads the image. Fine.

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?
__________________

Custom Software | Server Management | Integration and Technology Solutions
https://www.2much.net
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2018, 09:31 AM   #10
freecartoonporn
Confirmed User
 
freecartoonporn's Avatar
 
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.
freecartoonporn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2018, 09:57 AM   #11
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,633
Quote:
Originally Posted by freecartoonporn View Post
//get all images

//loop through all images src value

//change src value to new value.

//end.
Yes, almost. Change src value WITHIN the loop to new value. repeat, then end.
__________________

Custom Software | Server Management | Integration and Technology Solutions
https://www.2much.net
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2018, 10:49 AM   #12
blackmonsters
Making PHP work
 
blackmonsters's Avatar
 
Industry Role:
Join Date: Nov 2002
Location: 🌎🌅🌈🌇
Posts: 20,240
Quote:
Originally Posted by 2MuchMark View Post
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:

<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
blackmonsters is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2018, 11:12 AM   #13
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,060
Quote:
Originally Posted by 2MuchMark View Post
Hi Sarah,

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.
First, it is not sarah. You should know better.

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:
Originally Posted by blackmonsters View Post
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>
That would be close to what he wants except you are assuming that the images are already on the page.

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2018, 12:55 PM   #14
sarettah
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!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2018, 04:22 PM   #15
iceboi
Confirmed User
 
Industry Role:
Join Date: Oct 2017
Posts: 302
Is this on the server side or client side? Are you using node.js?
iceboi is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2018, 06:35 PM   #16
blackmonsters
Making PHP work
 
blackmonsters's Avatar
 
Industry Role:
Join Date: Nov 2002
Location: 🌎🌅🌈🌇
Posts: 20,240
Quote:
Originally Posted by sarettah View Post
That would be close to what he wants except you are assuming that the images are already on the page.

.
He said "The program doing it is outputting to HTML".
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
blackmonsters is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2018, 07:02 PM   #17
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,060
Quote:
Originally Posted by blackmonsters View Post
He said "The program doing it is outputting to HTML".
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.
That is not what I got from his description.

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!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
url, stupid, code, javascript, question, http://1something.jpg, file, titties, figure, insert, earthlings, http://something.jpg, image, program, generates, appears, img



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.