无法使中心弹出窗口正常工作

时间:2016-06-08 15:50:37

标签: javascript popup

这让我疯了。我是一个复制/粘贴的人(!)所以请温柔。

之前,我已经使用this solutionStack link)制作了一个完全有效的中心弹出窗口(在内部CMS网站上),但出于某种原因,我无法做到让它在新网站上工作(而不是在CMS上)。

我知道我错过了一些东西,但我无法看到它是什么!!

HTML:

<a class="twitter" href="https://twitter.com" onclick="PopupCenter(this.href,'myWindow','550','550');return false" target="_blank">Center Popup</a>

使用Javascript:

function PopupCenter(url, title, w, h) {  
    // Fixes dual-screen position                         Most browsers      Firefox  
    var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;  
    var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;  

    width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;  
    height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;  

    var left = ((width / 2) - (w / 2)) + dualScreenLeft;  
    var top = ((height / 2) - (h / 2)) + dualScreenTop;  
    var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);  

    // Puts focus on the newWindow  
    if (window.focus) {  
        newWindow.focus();  
    }  
}

JSFiddle

1 个答案:

答案 0 :(得分:0)

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Pop Up</title>
        <script src="popup.js"></script>
    </head>

    <body>
        <a class="twitter" href="https://twitter.com" onclick="PopupCenter(this.href,'myWindow','550','550');return false" target="_blank">Center Popup</a>
    </body>
</html>