Browsers can block access to window.top
due to same origin policy .
(由于相同的原始策略,浏览器可以阻止对window.top
访问。)
IE bugs also take place.(IE错误也会发生。)
Here's the working code:(这是工作代码:)
function inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
top
and self
are both window
objects (along with parent
), so you're seeing if your window is the top window.
(top
和self
都是window
对象(与parent
),因此您要查看窗口是否是顶部窗口。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…