使用JavaScript在新窗口中打开链接

时间:2011-04-22 09:38:38

标签: javascript html

嗨我有一个带有相应链接的Js图像转换器如何在新窗口中打开链接?

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

1 个答案:

答案 0 :(得分:0)

在js中使用window.open

打开新窗口

示例: - window.open(url, "", "toolbar=1, resize=1, scrollbars=1, status=1")


修改

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

修改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">')

在clickDir()方法中传递一些参数以了解要打开的URL。自己决定你想要通过什么。然后在clickdir方法中这样做:

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

这只是一个示例代码,您必须对其进行修改以满足您的需求。