美文网首页
window 多tab页跳转到指定tab页

window 多tab页跳转到指定tab页

作者: _嘿嘿_ | 来源:发表于2020-03-16 14:00 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <button onclick="openWindow()">打开新窗口</button>
    <button onclick="closeWindow()">关闭当前窗口</button>
    </body>
    <script type="text/javascript">
        var win;
        var openWindow = function () {
            win = win||[];
            //传入参数名字 打开的页面定义一个名字
            var name = "baidu";
            //目标页面
            var target = "http://baidu.com";
            //判断是否打开
            var flag = false;
            for(var i=0;i<win.length;i++){
              var objWin =  win[i];
              if(objWin.name === name){
                  flag = true;
                  //已经存在
                  objWin.win.location.replace(target);
                  objWin.win.focus();
                  break;
              }
            }
            if(!flag){
               var  cWin = window.open(target);
               var obj = {
                   name:'baidu',
                   win:cWin
               }
                win.push(obj);
            }
        }
        var closeWindow = function () {
            var userAgent = navigator.userAgent;
            if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {
                window.location.href="about:blank";
                window.close();
                history.back();
            } else {
                window.opener = null;
                window.open("", "_self");
                window.close();
            }
    
        }
    </script>
    </html>
    

    相关文章

      网友评论

          本文标题:window 多tab页跳转到指定tab页

          本文链接:https://www.haomeiwen.com/subject/lysgehtx.html