count number of levels of iframe nesting in cross-site situation
If my page is buried several iframes deep, is it possible to count how many levels down I am (cross-domain)?
(I'm prett开发者_如何学Cy sure the answer is "no".)
No, I'm almost certain there's no way to do that.
You might try something like
var current = window;
while (current.parent != current) {
current = current.parent;
}
, but I suspect you will fail with multiple domains, due to same origin policy.
Might be worth a shot, though. Maybe access is blocked to document contents only, and not to window object.
It's not the # of levels but in this way seems that you can identify if your content has been iframed more than once:
if (parent !== window) {
//I'm iframed once for sure
}
if (parent !== top) {
//I'm iframed more than once
}
Tested with Chrome 59, Safari 10, Firefox 54, Edge 15, IE11
精彩评论