简体   繁体   中英

How to detect if a site cannot be embedded via 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.

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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