JavaScript inside <a href= link

by "Art Zoller Wagner" <art(at)zollerwagner.com>

 Date:  Wed, 12 Mar 2003 15:29:28 -0500
 To:  "Basic HTML" <hwg-basics(at)hwg.org>
 References:  netzero
  todo: View Thread, Original
Hi,

I'm trying to get a piece of JavaScript to validate as DTD XHTML 1.0
Transitional.
This is a chunk of JS that writes my email address so it isn't plainly
available in the html.

With plain html, I used to have this in my pages and it validates as HTML
4.01 Transitional:

text<.script type="text/javascript" language="javascript">
window.document.write("<.a href='mailto:"+siteEmail+"'>email
me<.\/a>");<./script>
<.noscript>enable JavaScript so you can email me<./noscript>more text

(I've put a . after every <  Hope that works.)

That doesn't validate as XHTML 1.0 Transitional, seemingly because the w3
validator doesn't like my putting the script tag inside the link.

So I've tried this:
text <.a href='mailto: <.script type="text/javascript"
language="javascript">
window.document.write(siteEmail)</script><.script type="text/javascript"
language="javascript">
window.document.write(siteEmail)<./script>'><./a> more text

The validator accepts that with reservations about the < inside the link:
a.. Line 37, column 46: character "<" is the first character of a delimiter
but occurred as data
a.. Line 38, column 32: character "<" is the first character of a delimiter
but occurred as data

That seems pretty gawky. Is there a better way to do this?

TIA, AZW

HTML: hwg-basics mailing list archives, maintained by Webmasters @ IWA