Suppressing Javascript Errors, including iFrame Content

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)
            $("#bc_changed_" + idx.toString()).val("1");

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:

function silentErrorHandler(){return true;}

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.

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>

Leave a Reply