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

跟風遠走 提交于 2019-12-10 02:29:12

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8378896/how-to-detect-if-a-site-cannot-be-embedded-via-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!