CODEgrunt blog

Commentary and insight on web development and the Internet at large written with a wry smile and a hungry look.

the joys of disabling Javascript - Mon May 31, 2010

I suppose that I am paranoid by nature, at least with respects to web technologies. Javascript for example is obviously a powerful, feature friendly way of creating dynamic content but the idea of client side scripting that is not under the user's control has always made me a little nervous (the vast majority of browser exploits rely on it for example). So my default browsing environment is with ads blocked and Javascript disabled.

More and more these days I am seeing artifacts of new school web designers either confusing or forgetting that client side is not under their control and that not everyone (or every thing such as the plethora of bots out there) sees the world through rosy Javascript coloured glasses. Take the NHL's web designers for a Javascript-less ride and we get this:

nhl.com with Javascript disabled

What's in the red circle? Let us take a look:

nhl.com with Javascript disabled says "values were inserted here in example"
//values were inserted here in example

It is hard to tell whether someone was taking "copy and paste" too literally or whether a 3rd party is injecting content they should not be but none the less, it makes for an amusing and informative Google search.

The obvious lesson is do not forget to test your code with Javascript disabled because at the very least Google will.

carriage returns are false metal - Mon Nov 16, 2009

Ahh, carriage returns how I love thee. Today I managed to waste around 20 minutes banging my head against some very simple Javascript used to open a new window when the user clicks a link:

<a href="http://codegrunt.com" onclick="window.open(this.href); return false;">this is a link</a>

Trivial code, user clicks link and new window opens up. If life was only that simple - instead of the desired behaviour, the original URL was also firing and causing the originating window to load the URL as well. Arrrgh.

Can you see the bug? It is a trick question really as you would have probably have to view the source to notice it. The problem was a stray carriage return after "return" which causes Javascript to skip the return value of "false" and happily follow the link in both the current page and a new window. Now normally this would have been immediately obvious to me but my IDE is set up to nicely linewrap long lines which normally is pure awesome but unfortunately tricked me today when high LCD contrast (and perhaps not enough coffee) made the grey line wrap less obvious.

I hate these situations, something so simple going inexplicably astray. It becomes so easy to spiral off on dangerous tangents, "Oh no, maybe NoScript is doing something funny. . ." or "Crap, I bet something buried in an external library is messing with events!" Time consuming goose chases which could easily create their own mess as you wade frantically through trying to solve an issue that seems both impossible and ridiculous.

It has been a while but I again know how it feels to get punked by carriage returns.

adding bookmarks with Javascript - Fri Aug 14, 2009

I have added a new document discussing Javascript and bookmarks (it also acts as a landing page for those that click on the bookmark link with Javascript turned off).

adding a bookmark with Javascript

topics: javascript

blog

CODEgrunt consulting

Experienced PHP web developer.

$35 an hour, no job too small.

There is no replacement for integrity and experience.

Contact me for more information.

calendar

February 2012

Sun
Mon
Tue
Wed
Thu
Fri
Sat
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1
2
3