JohnstonM
JohnstonM

Reputation: 1

Hyperlink in js script inside HTML

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>

Upvotes: 0

Views: 63

Answers (3)

JohnPhoenix
JohnPhoenix

Reputation: 1

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'>

Upvotes: 0

radiaph
radiaph

Reputation: 4121

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

Upvotes: 0

Yash Thakur
Yash Thakur

Reputation: 1201

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

Upvotes: 1

Related Questions