Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

DHTML article deconstructed

Create Pop-Up Notes with DHTML is a disappointing new article on SitePoint which describes a technique for having a yellow Post-It style note appear when a link is clicked. The example given is for a link that shows the un-abbreviated form of NASA—a task better accomplished using the acronym tag. In addition, I spotted the following problems with the article:

  1. The link that triggers the popup note uses javascript: pseudo-protocol. This is bad! Scott Andrew posted a good rant about this back in May, and Evolt has an article explaining why onclick is the preferable alternative.
  2. Although the effect uses both CSS and a div element, the example code still recommends formatting the popup note using a fixed width table. This could be replaced by CSS styles on the div—a yellow background, some padding and a width declaration.
  3. The code uses visibility: hiddendisplay: none has better browser support and would have the same end effect (the code would then need to toggle it to display: block to make the note visible).
  4. The javascript uses document.all to reference the specified div by default, with object detection used to provide support for Netscape 4 (shudder) and Netscape 6/Mozilla. document.all was only ever used by IE, and IE5 and above support the standards compliant DOM equivalent, document.getElementById (which is also used by Mozilla). The only reason to use document.all is if you desperately need to support IE4, a browser who’s market share is even less than Netscape 4.

lloydi on the SitePoint forums made the excellent suggestion that the content of the notes should appear at the bottom of the page as footnotes, with the links that activate the popup notes doubling up as links to the footnote anchors. That way the content will stay accessible to user agents which do not support javascript.

This is DHTML article deconstructed by Simon Willison, posted on 7th December 2002.

View blog reactions

Next: W3C redesign

Previous: The best 404 page ever

4 comments

  1. Awful, dire article. I had to double-check that this was written 2 days ago, not 2 years. Apparently it was written by a "browser compatibility, Website usability, and optimization expert" - well she *really* needs to re-train in those skills.

    Tom Gilder - 7th December 2002 23:47 - #

  2. You're quite right, the code given is rotten. Additionally to your points:

    • positioning properties have lengths without a unit (180 instead of 180px);
    • browsers that support both document.all and document.getElementById (eg. Opera, Konqueror) will get no scripting at all due to the aforementioned idiotic browser-sniffing;
    • pop-ups are invisible if JavaScript is disabled.

    However, on the visibility vs. display issue I think you've got it muddled up: visibility is more widely supported than display; it works on browsers that don't reflow dynamically - which is Netscape 4 and Opera 6.

    Reading the position of a point in the text (in order to position a pop-up there) is something that standard DOM specs still don't quite let us do, though MouseEvents come infuriatingly close).

    However, a clever piece of script could grab the footnote elements from the bottom and put them in a nested-positioning arrangement (absolute inside relative) just next to their owner links... this would need proper DOM Core methods though (IE6, Moz, Op7, Konq3 etc).

    Andrew Clover - 12th August 2003 17:23 - #

  3. Testing out

    SD - 2nd February 2005 20:26 - #

  4. 1) I have multiple checkboxes in table. I want to check the value of each checkbox at run time using html + javascript. how to use getelementbyid.rows.cells 2) I want to retrieve the set of array values from javascript to .net. Could you help me? mail me plz, nellaikumar2002@rediffmail.com

    nellaikumar - 24th November 2005 07:09 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2002/12/07/dhtmlArticleDeconstructed

A django site