Suppressing Javascript Errors, including iFrame Content | Quisitive
Suppressing Javascript Errors, including iFrame Content
July 24, 2012
Quisitive
Put all of your Javascript code within try/catch statements.

Even though most browsers are configured to suppress Javascript errors, you want to ensure that you handle these errors effectively.

The best way to do this is to put all of your Javascript code within try/catch statements:

function HandleBillingCodeFieldChange(idx)
    {
        try
        {
            $("#bc_changed_" + idx.toString()).val("1");
        }
        catch(Exception){}
    }

In addition to that, it is always a good idea to have an overall Javascript error suppressor.  You probably only want to enable this in production, however, because it makes it more difficult to detect and fix Javascript errors in development:

I recently ran into an issue in which I was loading a SharePoint view into an iFrame in my application.  It was loading just fine, but it was throwing out a random JS conflict error, even though I had taken the above precautions.

function silentErrorHandler(){return true;}
window.onerror=silentErrorHandler;

I even tried adding an onerror event to my iFrame in an attempt to suppress the error, but it didn’t work.

I was, however, able to find the workaround for this in IE by adding a security=”restricted” attribute to my iframe:

<iframe name=”MyIFrame” id=”MyIFrame” src=”MySource.aspx” security=”restricted”></iframe>