javascript - window.opener.focus() fails in IE, and works in FireFox - Stack Overflow

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

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>

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>
Share Improve this question edited Oct 20, 2009 at 18:41 Ishmael 32.7k4 gold badges40 silver badges49 bronze badges asked May 18, 2009 at 7:05 GnosisGnosis
Add a ment  | 

2 Answers 2

Reset to default 2

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/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);

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744839818a4596488.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信