<?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>Endikos &#187; jQuery</title>
	<atom:link href="http://www.endikos.com/category/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://www.endikos.com</link>
	<description>Journeying through the art and science of digital media.</description>
	<lastBuildDate>Sun, 11 Jul 2010 23:53:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Link Targets, Web Standards, and jQuery</title>
		<link>http://www.endikos.com/web-standards/link-targets-web-standards-and-jquery.html</link>
		<comments>http://www.endikos.com/web-standards/link-targets-web-standards-and-jquery.html#comments</comments>
		<pubDate>Fri, 14 Nov 2008 20:12:51 +0000</pubDate>
		<dc:creator>Endikos</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.endikos.com/?p=10</guid>
		<description><![CDATA[[Note: This post has been moved to ThreeBit Media, my consulting website.]
As you may or may not be aware, XHTML 1.0 Strict does not include the old &#8220;target&#8221; attribute of a link.  In other words, you can no longer code thusly in order to tell the client browser that you&#8217;d like the clicked link to [...]]]></description>
			<content:encoded><![CDATA[<p><em>[Note: This post has been moved to ThreeBit Media, my consulting website.]</em></p>
<p>As you may or may not be aware, XHTML 1.0 Strict does not include the old &#8220;target&#8221; attribute of a link.  In other words, you can no longer code thusly in order to tell the client browser that you&#8217;d like the clicked link to open in a new window:</p>
<pre class="code">&lt;a href="http://some.domain"
           target="_blank"&gt;Clicky!&lt;/a&gt;</pre>
<p>So what does one do if you still want to open a link in a new window while still maintaining the integrity of your XHTML document? There have been many proposed solutions to this, but they basically devolve to two basic theories: 1) <a rel="external" href="http://www.sitepoint.com/article/standards-compliant-world/">Use javascript to make it work</a>; and 2) <a rel="external" href="http://www.accessify.com/features/tutorials/new-windows/">Extend the DTD to reinclude the old target attribute</a>.  I tend to agree more with using javascript to make it work.  Please don&#8217;t misunderstand.  In an ideal world, extending the DTD would be awesome.  Afterall, extensibility is part and partial to the whole XHTML idea.  But in practice, I fear this would introduce too many interoperability issues between browsers.</p>
<p><span id="more-10"></span></p>
<p>So in order to open links in new windows you mark the tag as an &#8220;external&#8221; link using the rel tag, like this:</p>
<pre class="code">&lt;a href="some.domain" rel="external"&gt;Clicky!&lt;/a&gt;</pre>
<p>Most articles I&#8217;ve read have been similar to the SitePoint article I linked to earlier, in that they use javascript like this to make any link tag with a rel attribute of &#8220;external&#8221; open in a new window:</p>
<pre class="code">&lt;script type="text/javascript"&gt;
  function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i&lt;anchors.length; i++) {
      var anchor = anchors[i];
      if (anchor.getAttribute("href") &amp;&amp;
        anchor.getAttribute("rel") == "external")
          anchor.target = "_blank";
    }
}
window.onload = externalLinks;
&lt;/script&gt;</pre>
<p>Enter jQuery. I&#8217;ve recently grown quite fond of this javascript framework.  It&#8217;s elegant and powerful.  While the above code is simple and straightforward,  I&#8217;m already using jQuery, so why not just let it do the heavy lifting?  We code it this way:</p>
<pre class="code">&lt;script type="text/javascript"&gt;
  $(function(){
    $("a[rel='external']").attr("target", "_blank");
    //update! '@' attribute syntax was deprecated
    //in jquery 1.2.  now just need the attribute
    //by itself.
  });
&lt;/script&gt;</pre>
<p>And in this manner, bliss is attained :-)  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endikos.com/web-standards/link-targets-web-standards-and-jquery.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
