Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript window.opener.focus()在IE中失败,在FireFox中工作_Javascript_Html_Window.opener - Fatal编程技术网

Javascript window.opener.focus()在IE中失败,在FireFox中工作

Javascript window.opener.focus()在IE中失败,在FireFox中工作,javascript,html,window.opener,Javascript,Html,Window.opener,我有个问题,我打电话时不能打开窗户 focus()方法 window.opener.focus();//之后,子窗口保持在前面。 html1.htm文件: <script type="text/javascript" language="JavaScript"><!-- function toCompare() { wCompare = window.open("html2.htm", "wCompare", "width=800,height=600,resizab

我有个问题,我打电话时不能打开窗户 focus()方法

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>
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;
   }
window.opener.focusAndGo(url);

返回父窗口

首先尝试模糊当前窗口,这可能会有所帮助

window.blur();
window.opener.focus();

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

html1.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>
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;
   }
window.opener.focusAndGo(url);
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>
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;
   }
window.opener.focusAndGo(url);

我试过了。这只是部分解决办法。window.blur工作正常并隐藏了子窗口,但如果开启器窗口位于另一个窗口后面,则focus()不会将其带到前面:(