views:

1556

answers:

2

Hi, i have the problem that IE cant bring up opener window when i call opener.focus() method

window.opener.focus(); // After that, child window stay in front.


html1.htm file:

<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>
A: 

Try to blur the current window first, maybe that helps.

window.blur();
window.opener.focus();
Gidon
I have tried that. This is only partial solution.window.blur is working fine and hides the child window, but if opener window is behind some another window .focus() wont bring him to front.:(
+1  A: 

This works fine for me, but I have seen similar behavior. Try creating a function in the parent page that grabs it's own focus and changes the 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;
   }

and call this from html2.htm

window.opener.focusAndGo(url);
larson4