防止window.open刷新父窗口

时间:2013-04-04 18:50:17

标签: javascript jquery

当我呼叫window.open时,父窗口会刷新。我还没有看到任何关于如何防止这种情况发生的事情。任何帮助将不胜感激。

left = Number((screen.width/2)-(730/2)),
top = Number((screen.height/2)-(450/2));

var windowFeatures = 'location=0,menubar=0,resizable=0,scrollbars=0,status=0,width=700,height=500,top='+top+',left='+left;
    window.open('access-modal.html', '', windowFeatures);

win.moveTo(left, top);

2 个答案:

答案 0 :(得分:2)

编辑后我的帖子出现问题。最终解决方案是阻止默认操作。

$('.button').on('click', function(e) {

    e.preventDefault();

        left = Number((screen.width/2)-(730/2)),
        top = Number((screen.height/2)-(450/2));

        var windowFeatures = 'channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,width=700,height=500,top='+top+',left='+left;
            win = window.open('access-modal.html?env=' + Data.currentOauth + '&url=' + Data.currentAddr, '', windowFeatures);

        win.moveTo(left, top);
        win.focus();

    }

});

答案 1 :(得分:1)

我不确定这是否是你的编辑..我知道win.moveTo(左,上)有错误。 win未定义..以下代码适用于我。

<script language="javascript" type="text/javascript">
            function windowOpen() {
                left = Number((screen.width / 2) - (730 / 2)),
                top = Number((screen.height / 2) - (450 / 2));

                var windowFeatures = 'location=0,menubar=0,resizable=0,scrollbars=0,status=0,width=700,height=500,top=' + top + ',left=' + left;
                var win = window.open('access-model.htm', '', windowFeatures);

                win.moveTo(left, top);
            }
        </script>