newwindow.focus()作用

来源:百度知道 编辑:UC知道 时间:2024/06/03 00:09:24
在创建的子窗口中写内容,那么newWindow.focus()这句有什么用呢?我试了试,写不写的效果是一样的,怎么回事呢?
代码如下:
<html>
<head>
<title>在子窗口使用document.write()方法</title>
<script>
<!--
var newWindow;
function makeNewWindow(){
newWindow = window.open("","","status,height=200,width=300");
}

function subWrite() {
if(newWindow.closed){
makeNewWindow();
}
newWindow.focus();
var newContent = "<html><head><title>新的文档</title></head>";
newContent += "<body bgcolor='aqua'><h1>此文档是全新的。</h1>";
newContent += "</body></html>";
newWindow.document.write(newContent);
newWindow.document.close();
}

//-->
</script>
</head>
<body onload=&q

newWindow.focus(); 意思是你新触发打开的窗口获得焦点

一般的情况,当使用window.open打开的窗口,默认的焦点就是新窗口

所以感觉写不写一样.

但当你打开若干窗口的时候,你想直接查看编辑某个窗口

就让哪个获得焦点.