Re: xhtml and javascript

On Saturday, June 28, 2003, 3:07:46 PM, Jens Meiert wrote:
> > <p>Here is a
> > <script>
> > document.write("complete paragraph<");
> > document.write("/p>");
> > </script>
> 
> The silly thing is to generate markup by scripts (imagine if
> JavaScript is disabled). 

It's easy to jump to the conclusion that generating markup from script
is always an awful thing to do - but there are some cases where it's
extremely handy.

Imagine if you wanted to have an element on the page that only had a
point in existing when scripting is enabled, like, for instance, a
checkbox that allows all links on the page to open in a new window.

If the checkbox was in the HTML as it was, then it would actually
makes things worse for users with no scripting - they'd have a useless
and pointless checkbox.

You could of course use the DOM to generate the checkbox, but you'd
have to wait for onload to fire, which is a bad thing - it would mean
the page would most likely jump down when the checkbox was inserted,
and if for some freak reason the page didn't ever load (an endlessly
loading image, for example), then the checkbox would never appear.

-- 
Tom Gilder, http://tom.me.uk/
 Blog! http://blog.tom.me.uk/

Received on Saturday, 28 June 2003 16:51:43 UTC