<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Random and Irrelevant &#187; Javascript</title>
	<atom:link href="http://sgp.me.uk/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://sgp.me.uk</link>
	<description>Sam Pearson&#039;s weblog - irrelevant content randomly updated</description>
	<lastBuildDate>Fri, 18 Nov 2011 18:06:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Javascript mailto links</title>
		<link>http://sgp.me.uk/2005/06/07/javascript-mailto/</link>
		<comments>http://sgp.me.uk/2005/06/07/javascript-mailto/#comments</comments>
		<pubDate>Tue, 07 Jun 2005 09:34:00 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://sgp.me.uk/2005/06/07/javascript-mailto</guid>
		<description><![CDATA[I generate the <code>mailto:</code> link on my <a href="http://sgp.me.uk/sam/about/contact.html">contact page</a> using javascript.  The intention is to make my address less visible to address-harvesting web crawlers. <a href="http://sgp.me.uk/2005/06/07/javascript-mailto/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I generate the <code>mailto:</code> link on my <a href="http://sgp.me.uk/2005/04/15/contact/">contact page</a> using javascript.  The intention is to make my address less visible to address-harvesting web crawlers.  I have no idea how effective this is, but as I had never written any javascript before it seemed like a nice simple project to start with.</p>
<p>The function looks for elements with <code>id</code> attributes matching its argument list.  For the script to make sense these elements should be anchor tags without <code>href</code> attributes.  It replaces their contents with a link of the form <code>argument@domain</code> (<code>domain</code> should be set to something appropriate inside the script), so the original content of the tags should be the text to be displayed to user-agents that do not support javascript, so something like this: <code><a id="user">user [at] example [dot] com</a></code>, perhaps.</p>
<pre><code>/*
 * Copyright 2005, Sam Pearson <http://sgp.me.uk/sam>
 *
 * Available under the terms of the GNU Public License:
 * http://www.gnu.org/copyleft/gpl.html
 *
 */

function write_mailto_links() {
  var at = '@';
  var domain = 'sgp.me.uk';
  for  ( var i = 0 ; i < arguments.length; i++ ) {
    var user = arguments[i];
    var linktext = document.createTextNode( user + at + domain );
    if ( document.getElementById( user ) ) {
      var mlink = document.getElementById( user );
      var oldtext = mlink.firstChild;
      mlink.setAttribute('href', "mailto:" + user + at + domain);
      mlink.replaceChild( linktext, oldtext );
    }
  }
}</code></pre>
<p>I'm sure that there's a better way to do this, but this works so I'm using it for the time being.  I'd like to play around a bit more with javascript, but for various <a href="http://sgp.me.uk/uma" title="Here's one!">reasons</a> I haven't had the time recently.  Any <a href="http://sgp.me.uk/sam/about/contact.html">feedback</a> is appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://sgp.me.uk/2005/06/07/javascript-mailto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

