如何检测某个网站是否无法通过 iframe 嵌入?
我正在尝试在 iframe 中嵌入一些随机站点。我收到此错误:
Refused to display document because display forbidden by X-Frame-Options.
我愿意尊重他们的意愿而不嵌入它,但我希望能够检测到此设置,以便我可以尝试重新加载另一个页面。有没有一种简单的方法可以在 Javascript 中做到这一点?
I'm trying to embed some random sites in an iframe. I'm getting this error:
Refused to display document because display forbidden by X-Frame-Options.
I'm willing to respect their wishes and not embed it, but I'd like to be able to detect that this is set, so that I can try and reload another page. Is there an easy to way to do this in Javascript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 CURL 服务器端或使用 AJAX 请求来完成此操作。无论哪种方式,其想法都是您向相关网站发出请求,然后简单地检查响应是否包含
X-Frame-Options
。You can do it either using CURL server side or using AJAX request. Either way, the idea is that you make a request to the website in question and simply check whether the response contains
X-Frame-Options
.