CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Random images + on click move to another webpage (http://www.codingforums.com/showthread.php?t=273836)

niona 09-22-2012 02:15 PM

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>


vwphillips 09-22-2012 03:40 PM

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>


niona 09-22-2012 04:05 PM

Thank you :thumbsup:


All times are GMT +1. The time now is 06:30 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.