11

我正在使用window.open从父窗口打开一个子窗口。我希望子窗口保持在顶部,以便用户在父窗口中进行输入时可以参考它。这可以做到吗?我目前正在使用 Firefox,但如果它适用于所有浏览器,那将是一个额外的好处。

4

6 回答 6

4

这个弹出层也不错:DOMWindowDemo

于 2012-12-20T05:09:52.787 回答
4

如何使用弹出 div而不是打开新窗口?

于 2012-12-20T05:46:50.053 回答
0

是的,您可以通过在正文中为子窗口提供 onBlur="self.focus()" 的代码来执行此操作

    //Parent page...
    <html>
      <body>
      <a href="#" onClick="window.open('two.html','sdvwsv','width=200,height=200');">here...</a>
         </body>
     </html>


   //Child page...
         <html>
          <body onBlur="self.focus();">
               here...
              </body>
          </html>
于 2012-12-20T05:14:58.913 回答
0
<html>
    <script language="JavaScript">
    <!--
    function openWin(){
      var myBars = 'directories=no,location=no,menubar=no,status=no';

      myBars += ',titlebar=no,toolbar=no';
      var myOptions = 'scrollbars=no,width=400,height=200,resizeable=no,top=10, left=10,';
      var myFeatures = myBars + ',' + myOptions;
      var myReadme = 'This is a test.'

      var newWin = open('', 'myDoc', myFeatures);

      newWin.document.writeln('<form>');
      newWin.document.writeln('<table>');
      newWin.document.writeln('<tr valign=TOP><td>');
      newWin.document.writeln('<textarea cols=45 rows=7 wrap=SOFT>');
      newWin.document.writeln(myReadme + '</textarea>');
      newWin.document.writeln('</td></tr>');
      newWin.document.writeln('<tr><td>');
      newWin.document.writeln('<input type=BUTTON value="Close"');
      newWin.document.writeln(' onClick="window.close()">');
      newWin.document.writeln('</td></tr>');
      newWin.document.writeln('</table></form>');
      newWin.document.close();
      newWin.focus();
    }
    -->
    </script>
    <body>
    <form>
      <b>Click the following button to open a new window: </b>
      <input type=BUTTON value="Open" onClick='openWin()'>
    </form>
    </body>
于 2012-12-20T05:18:18.483 回答
0

我为此挣扎了很长时间。这似乎是FF中的一个错误,但我注意到在新窗口打开后,如果我单击它,它确实会获得焦点并到达顶部。但是在它上面调用 window.focus() 没有用,所以我猜它发生得太早了。

所以在新窗口代码中,在我添加的页面底部

setTimeout(function(){window.focus()},100);

这感觉不像是扎实的练习,但如果你需要它来工作...... 100mSec 似乎是我系统上工作的最低速度。

于 2013-12-13T18:40:07.583 回答
-1
<html>
    <script language="JavaScript">
    <!--
    function openWin(){
      var myBars = 'directories=no,location=no,menubar=no,status=no';
      myBars += ',titlebar=no,toolbar=no';
      var myOptions = 'scrollbars=no,width=600,height=400,resizeable=no,top=10, left=10';
      var myFeatures = myBars + ',' + myOptions;
      var newWin = open('test.html', '', myFeatures);
      newWin.document.close();
      newWin.focus();
    }
    -->
    </script>
    <body>
    <form>
      <b>Click the following button to open a new window: </b>
      <input type=BUTTON value="Open" onClick='openWin()'>
    </form>
    </body>
</html>
    </html>
于 2012-12-20T05:24:05.930 回答