self
收藏:0
阅读:67
Window self 属性
定义和用法
self 属性可返回对窗口自身的只读引用。
语法
window.self
浏览器支持
所有主要浏览器都支持 self 属性
实例
当点击"Check window"按钮,check()被调用,并检查当前窗口的状态:
<html>
<head>
<script>
function check()
{
if (window.top!=window.self)
{
document.write("<p>This window is not the topmost window! Am I in a frame?</p>")
}
else
{
document.write("<p>This window is the topmost window!</p>")
}
}
</script>
</head>
<body>
<input type="button" onclick="check()" value="Check window">
</body>
</html>
<head>
<script>
function check()
{
if (window.top!=window.self)
{
document.write("<p>This window is not the topmost window! Am I in a frame?</p>")
}
else
{
document.write("<p>This window is the topmost window!</p>")
}
}
</script>
</head>
<body>
<input type="button" onclick="check()" value="Check window">
</body>
</html>