简体   繁体   English

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

[英]How to detect if a site cannot be embedded via iframe?

I'm trying to embed some random sites in an iframe. 我正在尝试在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? 有没有一种简单的方法可以在Javascript中执行此操作?

You can do it either using CURL server side or using AJAX request. 您可以使用CURL服务器端或AJAX请求来完成。 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 . 无论哪种方式,您都可以向相关网站提出请求,然后只需检查响应中是否包含X-Frame-Options

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM