Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Random images + on click move to another webpage

    Hello everyone!
    I have a couple of pictures, that should be changed automatically in some seconds. This JS code I have. But I would like to improve this code. If person likes appeared photo then by clicking on it, he should be sent to appropriate webpage (ie. webpage subpage).
    But when I'm trying to add some info, JS stops working.
    Code:
    <html>
    <head>
    <script type="text/javascript">
    <!--
    var image1=new Image()
    image1.src="first.png"
    
    //PROBLEM IS HERE
    //doing something like image1.src="<a 
    //href="http://www.google.com">"first.png"</a> doesn't help me...why?
    
    var image2=new Image()
    image2.src="second.jpg"
    
    var image3=new Image()
    image3.src="sun.JPG"
    //-->
    </script>
    </head>
    <body>
    <img src="first.png" name="slide" />
    <script>
    <!--
    //variable that will increment through the images
    var step=1
    function slideit(){
    //if browser does not support the image object, exit.
    if (!document.images)
    return
    document.images.slide.src=eval("image"+step+".src")
    if (step<3)
    step++
    else
    step=1
    //call function "slideit()" every 2.5 seconds
    setTimeout("slideit()",2500)
    }
    slideit()
    //-->
    </script>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <html>
    <head>
    <script type="text/javascript">
    <!--
    var image1=new Image()
    image1.src="http://www.vicsjavascripts.org.uk/StdImages/Egypt5.jpg";
    
    //PROBLEM IS HERE
    //doing something like image1.src="<a
    //href="http://www.google.com">"first.png"</a> doesn't help me...why?
    
    var image2=new Image()
    image2.src="http://www.vicsjavascripts.org.uk/StdImages/Egypt6.jpg";
    
    var image3=new Image()
    image3.src="http://www.vicsjavascripts.org.uk/StdImages/Egypt7.jpg";
    
    var LinkArray=['Link1.htm','Link2.htm','Link3.htm'];
    //-->
    </script>
    </head>
    <body>
    <a><img src="first.png" name="slide" border="0" /></a>
    <script>
    <!--
    //variable that will increment through the images
    var step=1
    
    function slideit(){
    //if browser does not support the image object, exit.
     if (!document.images)
      return
      var img=document.images.slide,lk=img.parentNode;
      lk.removeAttribute('href');
      if (LinkArray[step-1]){
       lk.href=LinkArray[step-1];
      }
     img.src=window["image"+step].src;
     if (step<3)
      step++;
     else
      step=1;
    //call function "slideit()" every 2.5 seconds
     setTimeout("slideit()",2500)
    }
    slideit()
    //-->
    </script>
    </body>
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •