I'd like to load external websites within an iframe, and if any of those sites employ the use of a frame blocker then I'd like to redirect the user to an error page. There have been a few proposed methods of doing this:
- wait for an onload timeout
- see if iframe src html contents are 'empty' after it loads
- Try to catch an error
- Maintain a database of 'blacklisted' urls
So far, depressingly, I've had the most luck with the last item. The other methods aren't working for the following reasons:
- waiting for an onload timeout:
- onload events fire even with websites that employ frame killers. For example, if I try to access www.google.com, it'll just load empty html structure.
- seeing if iframe src html contents are 'empty' after it loads
- You're unable to access external src contents of an iframe due to the same origin policy.
- Trying to catch an error:
- To my understanding I can only find error handling functions that pertain to errors stemming from your local JS code, and nothing related to errors like
"Refused to display <URL> in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
/'DENY'"
.
- To my understanding I can only find error handling functions that pertain to errors stemming from your local JS code, and nothing related to errors like
- Maintaining a database of 'blacklisted' urls:
- This is obviously a bad solution, it's incomprehensive and a big list haha.
Maybe I'm misunderstanding one of these methods. Is there a solution here I'm missing? For context I am doing this mainly in JS + jQuery.