开发者

Open links in new window with JavaScript

hi I have a Js image changer with corresponding links how to I open links in new window ?

     <script type="text/javascript">

        //#1 SPECIFY number of slideshows
        var number_of_slideshows=3

        // (2000=2 seconds)
        var interval=3500

        //#3 SHOULD each slide be linked to a unique URL
        var linked=1

        var slideshows=new Array(number_of_slideshows)
        for (i=0; i <number_of_slideshows; i++)
        slideshows[i]=new Array()

        //#4 SPECIFY image paths of 1st slideshow
        slideshows[0][0]='images/brownie.png'
        slideshows[0][1]='images/land.jpg'
        slideshows[0][2]='images/palmer.jpg'
        slideshows[0][3]='images/add.jpg'


        var slidelinks=new Array(number_of_slideshows)
        for (i=0; i <number_of_slideshows; i++)
        slidelinks[i]=new Array()

        //#5 SPECIFY urls of 1st slideshow
        slidelinks[0][0]='http://www.browning.com'
        slidelinks[0][1]='http://www.lakelandfishery.com'
        slidelinks[0][2]='http://www.palmeroni.com'
    开发者_高级运维    slidelinks[0][3]='http://www.palmeroni.com'



        function clickredir() 

{ window.open("http://www.browning.com","","") window.open("http://www.lakelandfishery.com","","") window.open("http://www.palmeroni.com","","") window.open("http://www.palmeroni.com","","")

}

</script>

          <script>

        var maininc=0
        var subinc=0

        if (linked)
        document.write('<a href="javascript:clickredir()"><img src="'+slideshows[0][0]+'" name="multislide" border=0></a>')
        else
        document.write('<img src="'+slideshows[0][0]+'" name="multislide">')

        function slideit(){
        subinc= (subinc<slideshows[maininc].length-1)? subinc+1: 0
        document.images.multislide.src=slideshows[maininc][subinc]
        }

        function setslide(which){
        clearInterval(runit)
        maininc=which
        subinc=0
        runit=setInterval("slideit()",interval)
        }

        runit=setInterval("slideit()",interval)

        </script>


To open new window in JS use window.open

Example: window.open(url, "", "toolbar=1, resize=1, scrollbars=1, status=1")


Edit

if (linked)
  document.write('<a href="javascript:window.open(slidelinks[0][0],"","")"><img src="'+slideshows[0][0]+'" name="multislide" border=0></a>')
else
  document.write('<img src="'+slideshows[0][0]+'" name="multislide">')

Edit 2

if (linked)
  document.write('<a href="javascript:clickredir(0,0)"><img src="'+slideshows[0][0]+'" name="multislide" border=0></a>')
else
  document.write('<img src="'+slideshows[0][0]+'" name="multislide">')

Pass some parameter in clickDir() method to know which url to open. Decide it yourself what you want to pass. And then in clickdir method do like this:

function clickredir(i,j) 
{ window.open(slidelinks[i][j],"","") }

It's just a sample code you have to modify it to meet your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜