【问题标题】:How to detect if Javascript is running in an cross-domain IFrame in Opera?如何检测 Javascript 是否在 Opera 的跨域 IFrame 中运行?
【发布时间】:2012-10-09 10:08:57
【问题描述】:

如何检测 JavaScript 是否在 Opera 的跨域 IFrame 中运行? 如果我尝试测试 if(typeof iframe.parent.document === 'undefined') Opera 12 似乎只是给出“未处理的错误:Security error: attempted to read protected”,它无法被代码捕获,从而中断执行。

【问题讨论】:

  • 它应该是可捕获的。你能给出一些没有被抓到的示例页面吗?

标签: javascript iframe cross-domain opera


【解决方案1】:

你不能。但是,如果您的目标是阻止其他域中的人将您的页面嵌入 iframe,则可以发送一个 http 标头来防止这种情况发生。

https://developer.mozilla.org/en-US/docs/The_X-FRAME-OPTIONS_response_header

大多数现代浏览器都支持它。它允许您指定允许哪些网站将您的页面嵌入 iframe。

【讨论】:

    猜你喜欢
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 2022-06-24
    • 2015-06-08
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多