<?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>ThreeBit Media &#187; jQuery</title>
	<atom:link href="http://www.threebit.com/blog/category/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://www.threebit.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 24 Sep 2011 21:23:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>jQuery Link Target Automation</title>
		<link>http://www.threebit.com/blog/web-standards/jquery-link-target-automation.html</link>
		<comments>http://www.threebit.com/blog/web-standards/jquery-link-target-automation.html#comments</comments>
		<pubDate>Mon, 26 Jul 2010 15:35:43 +0000</pubDate>
		<dc:creator>Bill Knechtel</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.threebit.com/blog/?p=78</guid>
		<description><![CDATA[In a post I wrote back in November 2008, I taught you how jQuery can be used to make links open in a new window in a standards compliant way, using the &#8220;rel&#8221; attribute in your link tag.  In my efforts to build and run a photography news website recently, it quickly became clear that [...]]]></description>
			<content:encoded><![CDATA[<p>In a post I wrote back in November 2008, I taught you how j<a href="http://www.threebit.com/blog/web-standards/link-targets-web-standards-and-jquery.html">Query can be used to make links open in a new window in a standards compliant way</a>, using the &#8220;rel&#8221; attribute in your link tag.  In my efforts to build and run a <a rel="external" href="http://www.phototimes.net">photography news website</a><!-- Isn't it ironic?  I'm giving an example of how to automate the external process, but am doing the older, manual way here in that very post!  It's deliberate, I assure you, to see who would notice. --> recently, it quickly became clear that I didn&#8217;t want to mark all my external links with &#8220;rel=external&#8221; , because every single post has an external link. Being thusly motivated, I started looking for wordpress plugins that would scan the link, determine if it was external, and do something to it in a standards compliant way that would make it open in a new window.  Coming up with diddly-squat on the search, I realized I was being dense. Again. I could let jQuery do that for me, and not have to install a plugin to do it.  Here&#8217;s the relevant code:</p>
<pre class="js" name="code">&lt;script type="text/javascript"&gt;
  $(function() {
    $("a:not([href^='http://www.phototimes.net'])").attr("target", "_blank").addClass("external-link");
  });
&lt;/script&gt;</pre>
<p>This little snippet does several things all at once. The first thing it does is find all links whose href  attribute does not begin with http://www.phototimes.net.  This selects links that are off-domain, which we want to open in a new window.  The next part sets the target attribute of the link to _blank, so that it will open in a new window, and the third part adds the external-link class to the tag.  The external-link class allows us to style the link differently that other links on the site, like adding one of those nifty little arrows that visually indicate that the link is offsite, and was popularized by Wikipedia.  jQuery, I think I love you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.threebit.com/blog/web-standards/jquery-link-target-automation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Link Targets, Web Standards, and jQuery</title>
		<link>http://www.threebit.com/blog/web-standards/link-targets-web-standards-and-jquery.html</link>
		<comments>http://www.threebit.com/blog/web-standards/link-targets-web-standards-and-jquery.html#comments</comments>
		<pubDate>Fri, 14 Nov 2008 21:12:50 +0000</pubDate>
		<dc:creator>Bill Knechtel</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.threebit.com/blog/?p=16</guid>
		<description><![CDATA[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: &#60;a href="http://some.domain" target="_blank"&#62;Clicky!&#60;/a&#62; So what does [...]]]></description>
			<content:encoded><![CDATA[<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 name="code" class="html">&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-16"></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 name="code" class="html">&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 name="code" class="js">&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 name="code" class="js">&lt;script type="text/javascript"&gt;
  /* Reflects jQuery 1.3 syntax */
  $(function(){
    $("a[rel='external']").attr("target", "_blank");
  });
&lt;/script&gt;</pre>
<p>And in this manner, bliss is attained :-)  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.threebit.com/blog/web-standards/link-targets-web-standards-and-jquery.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

