Window focus() 方法

定義和用法
focus() 方法可把鍵盤焦點給予一個窗口。
語法
window.focus()
流覽器支持
所有主要流覽器都支持 focus() 方法
實例
實例
確保新窗口獲得焦點(發送新窗口前):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function openWin(){
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>這是'我的窗口'</p>");
myWindow.focus();
}
</script>
</head>
<body>
<input type="button" value="打開窗口" onclick="openWin()" />
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function openWin(){
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>這是'我的窗口'</p>");
myWindow.focus();
}
</script>
</head>
<body>
<input type="button" value="打開窗口" onclick="openWin()" />
</body>
</html>

更多實例
