Here is the situation:
- A page (
iframe.html) has an iframe loading another page (iframe-content.html). - An JavaScript error might happen when
iframe-content.htmlis loaded in the iframe. - I’d like that exception to be visible to the browser (e.g. shown in Firefox error console, or Firebug).
Here is what I see:
- When
iframe.htmlis initially loaded, and loadsiframe-content.htmlwithsrc='iframe-content.html', the JavaScript exception shows in Firebug. - However, if the page is loaded in JavaScript (
document.getElementById('iframe').src = 'iframe-content.html'), the exception doesn’t show.
You can reproduce this by going to:
- http://avernet.googlepages.com/iframe.html with Firefox.
- You’ll see the exception as
iframe-content.htmlis loaded. - Click on the button: the content of the iframe is loaded again, but this time the exception doesn’t show in Firebug.
Is there a way at #3 to have the exception show, instead of it being silently ignored? (You can’t use a try/catch around the JS code that sets the src, as this code returns immediately before the page is loaded in the iframe.)
It seems that your iframe page is not really loaded on the second time. Or it’s loaded from the cache and the error is ignored. This is interesting, but I think I found an way around it.
With that the error should appear.
What I did, was to trick the browser to think that I’m loading a brand new page as the parameters after the url have changed.
You could replace my ‘bar’ string with a changing timestamp. Sure, it would avoid the cache, but it would also force it to generate the error like you wished.