Window self 屬性
定義和用法
self 屬性可返回對窗口自身的只讀引用。
語法
window.self
瀏覽器支持
所有主要瀏覽器都支持self 屬性
實例
實例
當點擊"Check window"按鈕,check()被調用,並檢查當前窗口的狀態:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.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>本教程(w3big.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>
嘗試一下»
Window對象