window.opener.focus () не работает в IE и работает в FireFox - PullRequest
1 голос
/ 18 мая 2009

У меня проблема в том, что IE не может открыть окно при открытии Метод opener.focus ()

window.opener.focus (); // После этого дочернее окно остается впереди.


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>

Ответы [ 2 ]

2 голосов
/ 18 мая 2009

Это прекрасно работает для меня, но я видел подобное поведение. Попробуйте создать функцию на родительской странице, которая захватит свой фокус и изменит 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);
0 голосов
/ 18 мая 2009

Сначала попробуйте размыть текущее окно, может быть, это поможет.

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