Posts

Showing posts with the label Same Origin Policy

Catch Error If Iframe Src Fails To Load . Error :-"Refused To Display 'http://www.google.co.in/' In A Frame.."

Answer : You wont be able to do this from the client side because of the Same Origin Policy set by the browsers. You wont be able to get much information from the iFrame other than basic properties like its width and height. Also, google sets in its response header an 'X-Frame-Options' of SAMEORIGIN. Even if you did an ajax call to google you wont be able to inspect the response because the browser enforcing Same Origin Policy. So, the only option is to make the request from your server to see if you can display the site in your IFrame. So, on your server.. your web app would make a request to www.google.com and then inspect the response to see if it has a header argument of X-Frame-Options. If it does exist then you know the IFrame will error. I think that you can bind the load event of the iframe, the event fires when the iframe content is fully loaded. At the same time you can start a setTimeout, if the iFrame is loaded clear the timeout alternatively let th...