ihtml5 / blog

个人博客 源码阅读*前端实践 My Blog
MIT License
6 stars 0 forks source link

如何确保页面始终在一个窗口中打开 #18

Open ihtml5 opened 7 years ago

ihtml5 commented 7 years ago

用途

页面始终在一个窗口中打开

Code

    var mainWin = null;
   // window.open有窗口菜单配置项时,为新窗口打开,否则是标签页打开
    function newFullscreenWindow(action, name) {
        if (mainWin == undefined || mainWin == null || mainWin.closed) {
            mainWin = window.open(action, "_blank");
            mainWin.moveTo(0, 0);
            mainWin.resizeTo(screen.width + 20, screen.height);
            mainWin.focus();
            console.log(mainWin.document);
        } else {
            mainWin.close();
            mainWin = window.open(action, "_blank");
            mainWin.moveTo(0, 0);
            mainWin.resizeTo(screen.width + 20, screen.height);
            mainWin.focus();
            mainWin.document.location.reload();
        }
    }
   //  事件代理,拦截链接点击默认行为,改为新窗口打开
    $('table').on('click',function(event) {
        if(event.target.tagName === 'A') {
            event.preventDefault();
            newFullscreenWindow(event.target.href);
        }
    });