问题
I am using window.open
to open a child window from the parent window. I want the child window to stay on top so the user can refer to it while making an entry in the parent window. Can this be done? I'm using Firefox at the moment, but it would be a bonus if it worked in all browsers.
回答1:
How about using a popup div instead of opening a new window?
回答2:
this popup layer is also good: DOMWindowDemo.
回答3:
yes you can do this by this code you have give onBlur="self.focus()" in body for child window
//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>
回答4:
<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>
回答5:
<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>
回答6:
I wrestled with this for a long time. It seems to be a bug in FF, but I noticed that after the new window opens, if I click on it, it does get focus and comes to the top. However calling window.focus() on it didn't work, so I guessed it was happening too early.
So in the new window code, at the bottom of the page I added
setTimeout(function(){window.focus()},100);
It does not feel like solid practice but if you need it to work... The 100mSec seems to be the lowest that works on my system.
来源:https://stackoverflow.com/questions/13965584/how-to-make-child-window-stay-on-top