Forum Moderators: open
<div title="Contact Us">
<span>
<script type="text/javascript">
document.write('<'+'a href="mailto:subscriber@');
document.write('domain.tld');
document.write('?subject=Contact Subscriber');
document.write('">Contact Us<'+'/a>');
</script>
</span>
</div>
The above script is adapted from HTML 4.0. The page containing it validates at W3C but the left-carat causes a warning in xhtml 1.0. Amaya reports it as a parsing error due to poorly formed code.
We have tried all manner of substitutes for the character--code and entity--but the same poorly formed code error continues to occur.
Is there an anti-harvesting script similar to the above that will work in xhtml?
We know this script works, since as soon as we inserted it in our pages, the spam stopped dead.
Okay, now for my next question, implementation:
The text for the link is obviously "contact us." This is not an 'onclick' event, so would the external script simply be called up to write the text to the browser and behave like any other link, as it does now? (Remember, you're dealing a greenhorn, here.)
I'm guessing, but I suppose my external .js file would look like this:
function contact(){ //contact us
document.write('<'+'a href="mailto:subscriber@');
document.write('domain.tld');
document.write('?subject=Contact Subscriber');
document.write('">Contact Us<'+'/a>');
}
Now to place it in the html, could I do something like this?:
<head>
.
.
<script type="text/javascript" src="jscript/mail.js"></script>
</head>
<body>
.
.
<div title="Contact Us">
<span>
contact()
</span>
</div>
I'm not clear on whether it would need to be written like this:
<div title="Contact Us">
<span>
<script type="text/javascript">
contact()
</script>
</span>
</div>
But it can be done in an even simpler way: Don't put anything in the head, just call the external .js where you need it to write:
<div title="Contact Us">
<span>
<script type="text/javascript" src="jscript/mail.js"></script>
</span>
</div>
and then don't bother with a function, just go straight in with the document.write stuff in the external file:
//contact us
document.write('<'+'a href="mailto:subscriber@');
document.write('domain.tld');
document.write('?subject=Contact Subscriber');
document.write('">Contact Us<'+'/a>');
What happens is the external .js gets executed exactly where you call it in the html document, and writes the mail stuff straight in!
I've tested it locally and it works fine.
This is now a sharable item. (I borrowed the original 4.0 code from Merijn.org, with his permission, of course, but he was unsure how to deal with the validation issue in xhtml.)
The original version had this variation which permitted displaying the actual e-addy in the browser:
document.write('<'+'a href="mailto:subscriber@');
document.write('domain.tld');
document.write('?subject=Contact Subscriber');
document.write('">subscriber@')
document.write('domain.tld<'+'/a>');
Thanks to Merijn, if you're reading this. And thanks DrDoc and PurpleMartin. You've been a big help and just made my day! (If you don't believe me, ask my wife!)