![]() Use a JavaScript library, such as jQuery, to make the function shorter.Use a different link identifier class – “email” is a little obvious!.Spammers can read this article and transform encoded emails just as easily as you! Use your own obfuscated email format, e.g.Although the example works, I suggest you: This intention of this article is to show the concept rather than real code. Anyone not running JavaScript will see the readable “bob (at) bobsdomain dot com” address.The majority of users (those with JavaScript enabled) will see a standard email address and “mailto:” link.Our original HTML page contains no “mailto:” links and cannot be easily harvested by spammers.Lines 25 and 26 then modify the DOM node and make it into a real “mailto:” link.įinally, we need to ensure the function runs on page load by adding a line to the bottom of email.js:.Line 22 checks the resulting email address is valid.Lines 17 to 19 transform it to a real email address using regular expressions: “dot” is changed to a “.”, “(at)” is changed to and all spaces are removed.Line 14 grabs the obfuscated email from the text content of the node.Line 11 checks the link for a class of “email”.Line 4 fetches every link in our HTML page and line 8 loops through them.Var link = document.getElementsByTagName & document.getElementsByTagName("a") Įmail = () || "" Įmail = email.replace(/(at)/ig, = email.replace(/s/g, "") The required code is short, so we do not need a JavaScript library: We will create a ’email.js’ file and include it in our HTML: The next step is to write a JavaScript function which searches your page for obfuscated emails and transforms them into real “mailto:” links. Note that we have included a class of “email” so our link can be identified. We will also make this a link to a contact page, e.g. The first step is to use a human-readable but harvester-proof email address in our HTML. (I would not recommend using document.write either.)Ī better solution is to use a combination of techniques to thwart spammers without causing user difficulties. Whilst this makes it difficult for spammers, it also makes it difficult for your users.Īnother option is to generate the email address using JavaScript, perhaps with a little string concatenation or encoding will stop most spammers, but anyone with JavaScript disabled will not see your address. The most obvious solution is to use a machine-unreadable email in your HTML, e.g. So how can you publish an email address without attracting unwanted attention from spammers? Use a “mailto:” today and your first viagra message will appear 30 seconds later. This was in the more innocent days of the web – before the spam harvesters took over. I could publish my address on a web page and anyone could email me with a single click. The day I discovered the “mailto:” link was glorious.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |