Window top 屬性

定義和用法
Top屬性返回當(dāng)前窗口的最頂層瀏覽器窗口。
語法
window.top
瀏覽器支持
所有主要瀏覽器都支持 top 屬性
實例
實例
當(dāng)點擊"Check window"按鈕,check()被調(diào)用,并檢查當(dāng)前窗口的狀態(tài):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool教程(w3cschool.cn)</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>W3Cschool教程(w3cschool.cn)</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>
嘗試一下 ?

更多建議: