My app allows users to view pages in an iframe, but pages like http://www.google.com, will generate an error
Refused to display document because display forbidden by
X-Frame-Options.
and pages like stackoverflow.com/questions/590163/how-to-get-all-options-of-a-select-using-jquery, will send me a alert saying:
For security reasons, framing is not allowed; click OK to remove the
frames.
How should I detect these situations and friendly tell user what happend with a genric message, such as “This page is restricted access, please directly access it from a new tab.’
This is because many site include frame buster. The error you are getting is most likely related to ajavascript process trying to access the parent window and getting an access denied error.
One of the possible solution will be to build a proxy on your server that fetch the html and serve it from your domain but many site won’t like that either and might even trouble you for it.