No more javascript alerts

I’ve been a web developer long enough to remember when window.console wasn’t a thing.  Then it appeared in Safari and Firebug, the awesome developer tool plugin for Firefox (that made Firefox my default development browser it was so good), but we had to object detect for it.  And Opera decided to go their own way and add window.opera.postError instead.

So what did we use instead?  window.alert – yes, that’s right, those horrible little popups that locked the UI and looked even worse than they do now…

These days all browsers (that I’m aware of – correct me if I’m wrong!) have a window.console for messages to be posted to (even ones that are quite fun), so hopefully you’re not adding any more window.alert‘s to your code base.  But what about legacy stuff?

Try this little fix…

window.alert = console.log

This redirects all messages to the console instead, avoiding the embarrassment and horror associated with an actual user seeing one of those little alerts.