问答详情
源自:2-5 JavaScript-打开新窗口(window.open)

请问如何实现一次点击打开多个窗口呢?

我觉得调用两次window.open()就行了,可是点击运行之后,之打开了第一个窗口

function open_win() {

window.open("https://c.runoob.com/","new");

window.open("http://www.runoob.com/","new1");

}


提问者:慕村9180196 2019-06-06 10:58

个回答

  • _漫漫前端路
    2019-06-14 22:10:15

    可以使用addEventListener为一个事件绑定多个响应函数
    <!DOCTYPE HTML>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>window.open</title>
            <script type="text/javascript"> 	
                window.onload = function(){	
                    var input = document.getElementsByTagName("input")[0];		
                    input.addEventListener("click",function(){window.open("https://c.runoob.com/","new");},false);		
                    input.addEventListener("click",function(){window.open("http://www.runoob.com/","new1");},false);	
                    }  
             </script>
         </head>
         <body>    
             <input name="button" type="button" value="点击我,打开新窗口!" / >
         </body>
    </html>


  • qq_慕仰2528744
    2019-06-06 14:11:56

    点击一个按钮只能打开一个窗口