如何检测某个网站是否无法通过 iframe 嵌入?

发布于 2024-12-19 23:49:51 字数 225 浏览 2 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

擦肩而过的背影 2024-12-26 23:49:51

您可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文