Nov
12
2023
js判断当前页面是否在iframe中
js判断当前页面是否在iframe中。
//方式一
if (self.frameElement && self.frameElement.tagName == "IFRAME") {
alert('在iframe中');
}
//方式二
if (window.frames.length != parent.frames.length) {
alert('在iframe中');
}
//方式三
if (self != top) {
alert('在iframe中');
}
最近在做一个项目,判断自身页面是否在iframe中,如果不存在,则让最顶部的窗口重定向一下
top.location.href = “https://www.phpernote.com/”;
微信扫一扫,打赏作者吧~