Window.opener.focus () doesn't work in IE and works in FireFox
I have a problem that IE cannot open the opener window when I call the opener.focus () method
window.opener.focus (); // After that, the child window stays 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>
+1
Gnosis
a source
to share
2 answers
This works great for me, but I've seen similar behavior. Try to create a function on the parent page that grabs its 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 it from html2.htm
window.opener.focusAndGo(url);
+2
a source to share