国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

window.parent與window.openner區(qū)別介紹

2024-05-06 14:22:07
字體:
供稿:網(wǎng)友
今天總結(jié)一下js中幾個(gè)對(duì)象的區(qū)別和用法:
首先來說說 parent.window與top.window的用法
"window.location.href"、"location.href"是本頁面跳轉(zhuǎn)
"parent.location.href"是上一層頁面跳轉(zhuǎn)
"top.location.href"是最外層的頁面跳轉(zhuǎn)
舉例說明:
如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js這樣寫
"window.location.href"、"location.href":D頁面跳轉(zhuǎn)
"parent.location.href":C頁面跳轉(zhuǎn)
"top.location.href":A頁面跳轉(zhuǎn)
現(xiàn)在終于明白了連接的時(shí)候target的用法了:
_blank:重新打開一個(gè)窗口
_parent:父窗口執(zhí)行重定向
_self:自身頁面重定向
_top:第一個(gè)父窗口重定向
綜上所述可知:parent.window:父窗口對(duì)象 top.window:第一個(gè)父窗口的對(duì)象
下面來重點(diǎn)看看window.parent與window.openner區(qū)別
window.parent 是iframe頁面調(diào)用父頁面對(duì)象,當(dāng)我們想從iframe內(nèi)嵌的頁面中訪問外層頁面是可以直接利用window.parent獲取;
例子如下:
A.html
代碼如下:
<html>
<head>
<title>父頁面</title>
</head>
<body>
<form id="form1" action="">
<div>
輸入值:
<input type="text" name="username" id="username" /><br />
<iframe src="b.html" width="400px" height="300px"></iframe>
</div>
</form>
</body>
</html>

B.html
代碼如下:
<html>
<head>
<script type="text/javascript">
function getpValue()
{
document.getElementByIdx_x_x_x("span1").innerText=window.parent.document.getElementByIdx_x_x_x("username").value;
}
</script>
</head>
<body>
<span>文本框值為:</span><span id="span1"></span><br />
<input type="button" value="獲取父窗口內(nèi)的文本框值" onclick="getpValue();">
</body>
</html>

window.opener 是window.open或超鏈接<a> 打開的子頁面調(diào)用父頁面對(duì)象
例子如下
a.html
代碼如下:
<html>
<head>
<title>父頁面</title>
<script type="text/javascript">
function openB()
{
window.open('b.html','b','width=400,height=200,status=no,toolbar=no,menubar=no,location=no,resizable=yes,left=200,top=100');
}
</script>
</head>
<body>
<form id="form1" action="">
<div>
輸入值:
<input type="text" name="username" id="username" /><br />
<input type="button" value="打開窗口B" onclick="openB();" /><br />
<a href="b.html" target="_blank">超鏈接打開B頁面</a>
</div>
</form>
</body>
</html>

b.html
代碼如下:
<html>
<head>
<script type="text/javascript">
function getpValue()
{
document.getElementByIdx_x_x_x("span1").innerText=window.opener.document.getElementByIdx_x_x_x("username").value;
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 得荣县| 荔波县| 开远市| 白朗县| 明水县| 昆山市| 富蕴县| 洞头县| 吉林市| 会理县| 鸡泽县| 玉环县| 封丘县| 赣榆县| 宁强县| 星子县| 凤冈县| 肇源县| 望都县| 新龙县| 淮安市| 湘乡市| 延川县| 安达市| 南充市| 绍兴市| 纳雍县| 麦盖提县| 偏关县| 昌乐县| 黄陵县| 丰镇市| 林口县| 吉林省| 玉林市| 迁西县| 油尖旺区| 广平县| 岑巩县| 昌江| 固原市|