Window top 屬性

定義和用法
Top屬性返回當前窗口的最頂層流覽器窗口。
語法
window.top
流覽器支持
所有主要流覽器都支持 top 屬性
實例
實例
當點擊"Check window"按鈕,check()被調用,並檢查當前窗口的狀態:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function check(){
if (window.top!=window.self) {
document.write("<p>這個窗口不是最頂層窗口!我在一個框架?</p>")
}
else{
document.write("<p>這個窗口是最頂層窗口!</p>")
}
}
</script>
</head>
<body>
<input type="button" onclick="check()" value="檢查窗口">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function check(){
if (window.top!=window.self) {
document.write("<p>這個窗口不是最頂層窗口!我在一個框架?</p>")
}
else{
document.write("<p>這個窗口是最頂層窗口!</p>")
}
}
</script>
</head>
<body>
<input type="button" onclick="check()" value="檢查窗口">
</body>
</html>
