Thoughts from the office by Ed Ball
Monday, August 25, 2003

Okay, I'm familiar with the use of the javascript: protocol for executing code in response to a hyperlink. What I didn't know is that if the code in question evaluates to anything but undefined, the content of the page gets replaced with that value! How I've gotten this far without knowing that simple fact is beyond me. For example:

<a href="javascript:DoSomething()">click here</a>

calls the DoSomething function, which is fine if DoSomething doesn't actually return something. If DoSomething returned true, for example, the page gets replaced by the text "true", which is almost certainly undesirable.

In any case, if you want to make sure that a javascript: link doesn't ever replace the content of the page, use the void operator like so:

<a href="javascript:void DoSomething()">click here</a>

Seems like a good habit to get into.

8/25/2003 3:29:33 PM (Pacific Daylight Time, UTC-07:00) | Comments [1] | Code#
3/16/2006 4:36:33 AM (Pacific Daylight Time, UTC-07:00)
Wow... that's a good one.
Daniel
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Search
Archive
Links
Categories
Administration
Blogroll