views:

37

answers:

2

Hi, I have a big flaw in my idea and was wondering if anyone cold help me. I have a script which i have wrote that runs on a page nicely. on that page there is an iframe, from which it's content is from a temporary web page ( temporary / dynamically generated for preview purposes ) which is in full working order ( i.e. it runs all it's javascripts / serverside code as it would normally ). I have no control on what content is being loaded via the iframe so my problem is this. if there is an error within the javascript code from the iframe ( this mainly applies to internet explorer ) then it stops the code from the parent running. Meaning im relying on people to be using correctly coded javascripts for them to be able to use my service.

Is there anyway to stop the iframe stopping the parents code working?

A: 
try {
    document.getElementById('iframe').src = 'iframe.html';
} catch (e) {
    //!!!
}
Sam Dark
sorry for such a late reply but I had to do some research. Like i said, I have no control on the data within the iframe, but surly its that javascript that needs to be wrapped in try{}???
Phil Jackson
Well, this way you will catch all possible errors in the iframe.
Sam Dark
A: 

You have to programmatically set the content in the iframe using javascript and do it in a try/catch block. So that any errors in the iframe will be caught and your script has effect on it.

See this post for more details

Teja Kantamneni