1

当我调用 opener.focus() 方法时,我遇到了 IE 无法调出开启器窗口的问题

window.opener.focus(); //之后,子窗口留在前面。


html1.htm文件:

<script type="text/javascript" language="JavaScript"><!--
function toCompare() {
    wCompare = window.open("html2.htm", "wCompare", "width=800,height=600,resizable=yes,directories=no,status=no,toolbar=no,menubar=0,location=no,scrollbars=yes");
    wCompare.focus();
};
//--></script>
</head>
<body>

<a href="javascript://" onClick="toCompare();">open child window</a>

</body>

html2.htm

<script type="text/javascript" language="JavaScript"><!--
      function show_Parent(url) {
          window.opener.location.href = url;
          window.opener.focus(); // After that, child window stay in front.
       }
    //--></script>
</head>
<body>

<a onclick="return show_Parent('html3.htm');">go back to parent window</a>

</body>
4

2 回答 2

2

这对我来说很好,但我看到了类似的行为。尝试在父页面中创建一个函数来获取它自己的焦点并更改 URL

html1.htm

function focusAndGo(url) {
   window.focus();
   // EDIT: changed document.location.href= to window.location.href=
   // Reference:
   // https://developer.mozilla.org/En/Document.location
   // document.location was originally a read-only property,
   // although Gecko browsers allow you to assign to it as well.
   // For cross-browser safety, use window.location instead.
   window.location.href=url;
   }

并从html2.htm调用它

window.opener.focusAndGo(url);
于 2009-05-18T12:57:49.117 回答
0

尝试先模糊当前窗口,也许会有所帮助。

window.blur();
window.opener.focus();
于 2009-05-18T07:21:10.667 回答