Jono Posted March 13, 2009 Report Posted March 13, 2009 There are quite a few sites that will let you encode your email address via JavaScript to show it on a web site without bots being able to find it, & therefore spam it (or at least it stems the tide). When you click on them it opens a new email message in the user?s email client with the email address in the ?to? field. What I want to do is display an email address on a web site & encode it in JavaScript (to help prevent spam), but I don?t want it to open a new email when clicked on (I want to activate some different JavaScript instead). Does anyone know if this would be possible? Quote
monkeysaurus Posted March 13, 2009 Report Posted March 13, 2009 Yes, it should be possible to do this. What you'll want to do is something like this: Email Me! This should work, but I haven't tested it. If you could post what you've got so far, I might be able to help further. Quote
Jono Posted March 13, 2009 Author Report Posted March 13, 2009 Actually, never-mind. I found the solution on the site where I encoded the original email address. But thanks a lot for trying to help Quote
monkeysaurus Posted March 13, 2009 Report Posted March 13, 2009 Would you mind posting the solution? It might be helpful for others searching. Quote
Jono Posted March 13, 2009 Author Report Posted March 13, 2009 Sure, I originally made the encoded email address with Enkoder. I didn't realise you could encode any html on the same page Quote
monkeysaurus Posted March 13, 2009 Report Posted March 13, 2009 Thank you. Oh, and I've just tested the solution above, and it seems to work. Quote
jlhaslip Posted March 14, 2009 Report Posted March 14, 2009 (edited) For those of you wanting a function to 'obfuscate' an email address, here is one sample: // obfuscate emails function function hexentities($str) { $encoded = ''; for($i = 0; $i $encoded .= ''.bin2hex(substr($str, $i, 1)).';'; } return $encoded; } Usage: $email = "myself@mydomain.com"; echo hexentities($email) ?> Displays 'myself@mydomain.com' on the html page as output to the screen/page, but the source code is hex encoded so 'most' Bots won't find the addresses. Never any guarantees in life, and the Bots are getting smarter all the time, too. See also: http://www.jlhaslip.trap17.com/samples/email/index.php View source that page and look at the Footer code to see a real example in use. Edited March 14, 2009 by jlhaslip Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.