在没有焦点的窗口下打开弹出窗口Jquery

时间:2015-09-23 09:16:07

标签: javascript jquery

我正在尝试在活动窗口选项卡下弹出一个窗口,但是当我这样做时会打开一个新选项卡并失去焦点。我要做的是打开一个新的弹出窗口/选项卡,但是父窗口的焦点仍然是

function displaypop() {

    var url = 'http://www.google.com';
    var windowName = "popUp"; //$(this).attr("name");
    var mypopup = window.open(url, windowName, "height=200,width=200");
    mypopup.blur();
    window.focus();


 }

1 个答案:

答案 0 :(得分:0)

您可以使用javascript实现此目的。不是一个漂亮的解决方案。

        var win = window.open("/apex/PopupWindow", "PopupWin", "height=500,width=500");
        // set the focus new window
        win.focus();
        // assign the methods focusPopup to the window events that may cause it to loose focus
        window.onmousedown = focusPopup;
        window.onkeyup = focusPopup;
        window.onmousemove = focusPopup;

        function focusPopup() {
            if (win && !win.closed) {
                win.focus();
            }
        }