Topics include: programming, Apple, Unix, gadgets, large-scale web sites and other nerdy stuff.

Why you should never use Javascript alerts, except for debugging

2007-11-06 09:19:59

I do not like Javascript alerts(). There are a number of big problems with them:

They are modal, and lock up the entire web browser in most implementations. Actually, all that I am aware of. Users can't hit the "back button" or even quit or close their browser normally when they are active. It's an obnoxious seizure of control by a program or website. It says: "Hey user, I am so important that I'm not going to let you do anything else until you deal with me." This might have had some twisted justification when people didn't use tabbed browsing. But now a browser is a container for multiple applications. Imagine if a modal dialog from one application on your computer locked out access to all the others. That would suck, no?

Furthermore, most alerts don't even give users more choices than "OK." They are just messages that the web site programmer has decided you REALLY MUST READ RIGHT NOW, and TELL ME WHEN YOU ARE DONE READING IT. Or no more fun for you. Javascript alerts are lazy alternatives to error pages. If you really want a user to read your error message, show them a page with nothing on it except your message, with a link back to continue. At least they can use the back button.

You don't really have any idea what a web browser implementation of alerts is going to be like. Sure, you know what MSIE will do, and maybe you also know firefox. What about Safari? Opera on Linux? A mobile browser? What about somebody with dual monitors? It's very likely, that in many cases, an alert box will not look like the rest of your site, and might even end up hidden behind another window. That's a fun experience for a user.

Then there is the worst case, the one that costs your business its marginal revenue and profits. That's what I ran into today, and it prompted this rant. Check out this screen:


Looks pretty harmless right? I should just fix my credit card number and move on. But no, this is an infinite loop of JS alerts. I click OK, and I get the same error again. I can't go back, because the dialog is modal and has locked out all browser controls. I can't go forward. I have to actually kill the browser and start over. But guess what? I'm feeling vindictive and angry so I go to amazon and pay $20 more for my hard drives. Petty, but satisfying.