JS代码:
//方式一
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 = "http://www.cnblogs.com/landfill/",

这些信息来源于http://justcoding.iteye.com/blog/2049127,非常感谢这篇文章的作者。

05-11 15:57