亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js實(shí)現(xiàn)網(wǎng)頁(yè)防止被iframe框架嵌套及幾種location.href的區(qū)別

 更新時(shí)間:2013年08月28日 16:42:57   作者:  
首先我們了解一下幾種location.href的區(qū)別簡(jiǎn)單的說:幾種location.href的區(qū)別js實(shí)現(xiàn)網(wǎng)頁(yè)被iframe框架功能,感興趣的朋友可以了解下
首先我們了解一下:window.location.href、location.href、self.location.href、parent.location.href、top.location.href他們的區(qū)別與聯(lián)系,簡(jiǎn)單的說:幾種location.href的區(qū)別 js實(shí)現(xiàn)網(wǎng)頁(yè)被iframe框架功能
"window.location.href"、"location.href"、"self.location.href"是本頁(yè)面跳轉(zhuǎn)
"parent.location.href"是上一層頁(yè)面跳轉(zhuǎn)
"top.location.href"是最外層的頁(yè)面跳轉(zhuǎn)

舉個(gè)例子說明(如上圖):
如果A,B,C,D都是普通頁(yè)面,D是C的iframe,C是B的iframe,B是A的iframe,
如果D中js這樣寫:
"window.location.href"、"location.href":D頁(yè)面跳轉(zhuǎn)
"parent.location.href":C頁(yè)面跳轉(zhuǎn)
"top.location.href":A頁(yè)面跳轉(zhuǎn)

如果D頁(yè)面中有form的話:
<form>: form提交后D頁(yè)面跳轉(zhuǎn)
<form target="_blank">: form提交后彈出新頁(yè)面
<form target="_parent">: form提交后C頁(yè)面跳轉(zhuǎn)
<form target="_top"> : form提交后A頁(yè)面跳轉(zhuǎn)

關(guān)于頁(yè)面刷新,D 頁(yè)面中這樣寫:
"parent.location.reload();": C頁(yè)面刷新 (當(dāng)然,也可以使用子窗口的 opener 對(duì)象來(lái)獲得父窗口的對(duì)象:window.opener.document.location.reload(); )
"top.location.reload();": A頁(yè)面刷新

現(xiàn)在回頭看看,js實(shí)現(xiàn)網(wǎng)頁(yè)防止被iframe框架功能就很簡(jiǎn)單了。假設(shè)frame.html文件中框架了content.html文件,那么思路是這樣的:在content.html中加入js檢測(cè)自己本身top.location.href地址,是否為top.location.href地址。如果是則沒被嵌套,如果否的話即被嵌套了,這是我們可以提示一下。預(yù)覽效果

網(wǎng)頁(yè)防止被框架方法代碼:
復(fù)制代碼 代碼如下:

<script language="javascript">
if(top.location!==self.location){
WarningTxt1 = "content頁(yè)面被iframe了!";
WarningTxt2 = "我們跳出iframe,直接訪問content頁(yè)面吧!";
alert(WarningTxt1);
alert(WarningTxt2);
top.location.href=self.location.href;
}
</script>

相關(guān)文章

最新評(píng)論