Latest web development tutorials

Window parent 屬性

Window 對象參考手冊 Window對象

定義和用法

parent屬性返回當前窗口的父窗口。

語法

window.parent


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持parent 屬性


實例

實例

當打開新窗口時,在父窗口彈出警告:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
</head>
<head>
<script>
function openWin(){
window.open('','','width=200,height=100');
alert(window.parent.location);
}
</script>
</head>
<body>

<input type="button" value="打開窗口" onclick="openWin()">

</body>
</html>

嘗試一下»


Window 對象參考手冊 Window對象