The Online Portfolio of Kevin Slodic

Javascript - To Use or Not to Use

Wednesday October 10, 2007

Should Javascript be used in websites? Absolutely. Should Javascript be relied upon in websites? Absolutely Not. Numerous blogs have been created around this subject (most notably this one from 456 Berea St. which I read the other day).

From experience, no one has the same browser setup as you (we do not live in an ideal world). Some people use Firefox, some people use Safari, some people use Opera, and most people use Internet Explorer. Each browser interprets Javascript a tad different from each other and each browser has the ability to turn Javascript on or off. How many people actually turn Javascript off? Not a whole lot, but more people than you might think (I don't have statistics on that, but I believe it to be true). Some people might turn off Javascript for security reasons, others may do it stop popup windows, and others may do it to speed up page loads. If your site doesn't work with Javascript turned off then chances are you'll see a loss of traffic.

One of my biggest problems with ASP .NET is that a lot of its controls and features rely on Javascript (the linkbutton, autopostback, datagrid paging, etc.). I've read you can override the controls and render what you want it to render, but to me it seems like more trouble than it's worth and it kind of defeats the purpose of using ASP .NET to simplify things for the developer.

All in all, I think Javascript is a wonderful tool that should be utilized, however, it should not be relied upon. If you want to open a popup window use something similar to this:

<a href="index.html" onclick="window.open(this.href,'','height=500,width=500'); return false;">Popup</a>

The return false tells the browser not to use the href, but if Javascript is disabled the href will be used.

I know this topic has been covered many times before, but I feel it to be important because of some projects I'm currently working on that are dependent on Javascript when they shouldn't be - not my decision.

View Comments