Click to See Complete Forum and Search --> : w3C Validation & JS
Beach Bum
09-05-2003, 10:09 AM
I am using this on a site to "hide" the email adress from bots. Works fine but does not pass W3C Validation.
The trick is, I want the email address to also be the text for the link (so making the href point to a function is not a complete solution).
<script type="text/javascript">
domain = "domain";
document.write('<a href="mailto:name@'+domain+'.com">name@'+domain+'.com</a>');
</script>
Not sure why I really care . . . but anyone know how to do this so it will pass validation?
I personally would use something like this, if you are concernted about that, as it will continue working for those with javascript disabled:
<a href="mailto:your&#64;your&#46;com">your&#64;your&#46;com</a>
Originally posted by Beach Bum
I am using this on a site to "hide" the email adress from bots. Works fine but does not pass W3C Validation.
The trick is, I want the email address to also be the text for the link (so making the href point to a function is not a complete solution).
<script type="text/javascript">
domain = "domain";
document.write('<a href="mailto:name@'+domain+'.com">name@'+domain+'.com</a>');
</script>
Not sure why I really care . . . but anyone know how to do this so it will pass validation?
To get it to work like that and still be valid, put <!-- and --> before and after you script so that it is commented out from the validator.
I would be concerned about getting spam when posting your email address or a mailto: link. The only time I have ever received spam mail (trust me, it was not good mail, either!) was when I had a mailto: link on a Web site; the moment I removed the link, I stopped receiving spam mail. That is my testimony, for what it's worth. ;)
Originally posted by pyro
I personally would use something like this, if you are concernted about that, as it will continue working for those with javascript disabled:
Yes, this suggestion is much better than that of the JavaScript idea; ensure that it is in quotes, otherwise a validation error will occur.
[J]ona
Originally posted by Jona
ensure that it is in quotes, otherwise a validation error will occur.Huh? The code I posted will validate fine...
Originally posted by pyro
Huh? The code I posted will validate fine...
It was in quotes. I was just noting that since most people tend to use <a href=mailto:you&#46;yourdomain.com>...</a> instead of <a href="mailto:you&#46;yourdomain.com">...</a>, and the proper way to do it is with the quotes, otherwise the validator says it's invalid.
[J]ona
Oh... I would recommend quoting all attribute values (and it is necessary to do that in XHTML)...
Originally posted by pyro
Oh... I would recommend quoting all attribute values (and it is necessary to do that in XHTML)...
Agreed.
[J]ona
Beach Bum
09-05-2003, 02:38 PM
Thanks . . . works great