I have JS script which loads the contents of a webpage inside an iframe like this:
$("#iframeid").attr( "src", url );
Now, there is a security error being thrown on the webpage at url
, due to cross-origin violation. The webpage has some JS code which tries to access window.parent
and fails because of cross-origin. Other than that the webpage loads fine.
I want to be able to catch this error in my script (and simply log it). I am trying to use try-catch as follows:
try {
$("#iframeid").attr( "src", url );
}
catch(err)
{
console.log(err);
}
but it does not catch the error. My guess is that the try code finishes executing before the webpage is loaded.
Is there a way for me to catch this error on my side at all? Thanks.