GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Stupid Javascript Question (https://gfy.com/showthread.php?t=1303974)

2MuchMark 09-27-2018 06:55 PM

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!

iceboi 09-27-2018 07:50 PM

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.

freecartoonporn 09-27-2018 08:02 PM

no question is stupid question.

lezinterracial 09-27-2018 10:49 PM

never mind what I said before.

Spunky 09-27-2018 10:58 PM

It will never work

2MuchMark 09-28-2018 12:42 PM

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*

CurrentlySober 09-28-2018 12:59 PM

Quote:

Originally Posted by freecartoonporn (Post 22341430)
no question is stupid question.

Unless I am the one asking it... :2 cents:

sarettah 09-28-2018 01:41 PM

Quote:

Originally Posted by 2MuchMark (Post 22341787)

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


.

2MuchMark 09-29-2018 08:57 AM

Quote:

Originally Posted by sarettah (Post 22341805)
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?

freecartoonporn 09-29-2018 09:31 AM

//get all images

//loop through all images src value

//change src value to new value.

//end.

2MuchMark 09-29-2018 09:57 AM

Quote:

Originally Posted by freecartoonporn (Post 22342090)
//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.

blackmonsters 09-29-2018 10:49 AM

Quote:

Originally Posted by 2MuchMark (Post 22341404)
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.


:thumbsup

sarettah 09-29-2018 11:12 AM

Quote:

Originally Posted by 2MuchMark (Post 22342077)
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 (Post 22342115)
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.

.

sarettah 09-29-2018 12:55 PM

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?

.

iceboi 09-29-2018 04:22 PM

Is this on the server side or client side? Are you using node.js?

blackmonsters 09-29-2018 06:35 PM

Quote:

Originally Posted by sarettah (Post 22342121)
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.

sarettah 09-29-2018 07:02 PM

Quote:

Originally Posted by blackmonsters (Post 22342257)
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 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