Window focus() 方法

定義和用法
focus() 方法可把鍵盤焦點給予一個窗口。
語法
window.focus()
瀏覽器支持
所有主要瀏覽器都支持 focus() 方法
實例
實例
確保新窗口獲得焦點(發(fā)送新窗口前):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool教程(w3cschool.cn)</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>W3Cschool教程(w3cschool.cn)</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>
嘗試一下 ?

更多實例

更多建議: