0

I'm a super noob and am trying to get the images in this slideshow to link to URLs.

I realize I should have created separate js and html files and I will do that but just want to see if it is possible like this.

THANK YOU!!!

<!doctype html>
<html>
<head>

<script type="text/javascript">
    var image=new Image()
    image[0]=new Image()
    image[0].src= "hello1.jpg" 
    image[1]=new Image()
    image[1].src="hello2.jpg"
    image[2]=new Image()
    image[2].src="hello4.jpg"
    image[3]=new Image()
    image[3].src="hello3.jpg"
    image[4]=new Image()
    image[4].src="hello5.jpg"
</script>

</head>

<body>

    <img  id="slide" width=1140 height=521 alt="image" />

    <script type="text/javascript">
        var step = 0
        function slideit(){
            if (!document.images)
                return

            document.getElementById('slide').src = image[step].src

            if (step<4)
                step++
            else
                step = 0

            setTimeout("slideit()",5500)
        }
        slideit()
    </script>

</body>
</html>
2
  • 1
    so when u click on an image , it should open a link ? or do u want to get images from a website? Commented Feb 12, 2015 at 5:23
  • 2
    Image should be an array the way you are referencing above when first initializing image it should be var image = []; Commented Feb 12, 2015 at 5:26

3 Answers 3

1

Give the img tag a <a href> attribute and make an array of links and when the image changes also change the href link.

Sign up to request clarification or add additional context in comments.

Comments

0
  ...
<body>

    <a id="slideLink"><img id="slide" width=1140 height=521 alt="image" /></a>

<script type="text/javascript">
    var step = 0
    function slideit(){
        if (!document.images)
            return

        document.getElementById('slideLink').href = document.getElementById('slide').src = image[step].src;
...

Comments

0

Simply put, from the code above, the browser doesn't know you want to click on the image, there are many ways to accomplish this, but by far the easiest, is to wrap each image tag, in a tag and the passing a URL to the href attribute of the a tag. Like so... http://www.somewhere.com'>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.