window.opener.focus() problem in FF5+

别说谁变了你拦得住时间么 提交于 2019-11-28 05:14:56

问题


I'm opening new window with next code: window.open(url,pageName1,"menubar=1,resizable=1,scrollbars=1,status=yes,width=1050,height=820");

so window is not modal

In new window I'm calling:

if (window.opener) window.opener.focus();

in IE, Chorme, FF3.6 parent window become in focus, BUT not in FF5 or FF6, how I can move focus to parent window?


回答1:


FF4+ prevernt window raising and lower by default, you can enable in options: Tools->Options->Content->Advanced... (in "Enable JavaScript" row)->Check "Raise or lower windows"




回答2:


I'm leaving here my contribution to anyone wants to open popup in background. The secret is open a blank page, then inject the desired url.

<script>
    var url = 'http://example.com/page.html';
    var popunder = w.open('about:blank',"window_example", "resizable=no,scrollbars=yes,height=600,width=800,status=yes,top=0,left=0");

    if(window.navigator.userAgent.match(/firefox/i)){ //fix for firefox browser
        popunder.document.write('<script type="text/javascript">window.opener.open("","_parent");location.replace("'+url+'");</script>');
        popunder.document.close();
    } else
        popunder.parent.location = url;

    popunder.blur();
    window.focus();
</script>           


来源:https://stackoverflow.com/questions/7281758/window-opener-focus-problem-in-ff5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!