统计跨站情况下iframe嵌套的层数
如果我的页面深埋了几个iframe,是否可以计算出我到底有多少层(跨域)?
(我很确定答案是“不”。)
If my page is buried several iframes deep, is it possible to count how many levels down I am (cross-domain)?
(I'm pretty sure the answer is "no".)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,我几乎可以肯定没有办法做到这一点。
您可能会尝试类似的方法
,但我怀疑由于同源政策,您会因多个域而失败。
不过,可能值得一试。也许仅阻止对文档内容的访问,而不阻止对窗口对象的访问。
No, I'm almost certain there's no way to do that.
You might try something like
, 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.
这不是级别数,但通过这种方式,您似乎可以识别您的内容是否已多次 iframe:
使用 Chrome 59、Safari 10、Firefox 54、Edge 15、IE11 进行测试
It's not the # of levels but in this way seems that you can identify if your content has been iframed more than once:
Tested with Chrome 59, Safari 10, Firefox 54, Edge 15, IE11