![](/img/trans.png)
[英]How to view a web page including JQuery with an iframe in Google Chrome
[英]Check if page is in Iframe for Google Chrome
我嘗試了window的許多屬性,以查看iframe中的頁面是否可以判斷它是否在iframe中。 我試過了:
if(top.location!= self.location) //doesn't work in Google Chrome
alert("I am in an iframe!")
而且這是行不通的(除了Chrome瀏覽器,其他瀏覽器都可以使用)。 我正在為Firefox和Chrome寫用戶腳本,但Chrome確實不起作用。 有沒有辦法判斷Chrome是否可以檢測其網頁是否位於iframe中?
這適用於框架,我認為它也適用於iFrame
if (top === self) {
// no frame
} else {
//frame
}
即使是最古老的瀏覽器也支持window.frameElement
。 它標識嵌入了當前窗口的iframe,嵌入或對象。
if(!!window.frameElement){
//code to be executed if we are in an iframe
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.