Saturday, January 9, 2010

Javascript with IE is painful

Most web developers know this is a painful combo: JS + IE = Pain.

Whenever a developer sees this on the lower left corner of the browser window:




he or she will be more likely sad. Double clicking on it will pop up a window telling you the javascript error that doesn't make sense (after clicking show details to show the error).


There is one time I encounter errors that are not consistent on every run. Although the javascript does what it is supposed to do, the errors keep showing up sometimes but not all the time. Since the javascript is doing what it is supposed to function both in IE and Firefox, I need a way to suppress the error.

Then I found this javascript:



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




This will suppress the error icon showing on the left corner of IE.

A good piece of trick to preserve a professional looking web site.







No comments:

Post a Comment