如何检测网站是否无法通过iframe嵌入? [英] How to detect if a site cannot be embedded via iframe?

查看:229
本文介绍了如何检测网站是否无法通过iframe嵌入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在iframe中嵌入一些随机网站。我收到此错误:

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.

我愿意尊重他们的意愿而不是嵌入它,但我希望能够检测到这是否已设置,以便我可以尝试重新加载另一个页面。有没有一种简单的方法在Javascript中执行此操作?

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?

推荐答案

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

这篇关于如何检测网站是否无法通过iframe嵌入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆