Latest web development tutorials

Window focus() 方法

Window 對象參考手冊 Window對象

定義和用法

focus() 方法可把鍵盤焦點給予一個窗口。

語法

window.focus()


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持focus() 方法


實例

實例

確保新窗口獲得焦點(發送新窗口前):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.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>

嘗試一下»


實例

更多實例

確保新窗口沒有獲得焦點


Window 對象參考手冊 Window對象