<?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>ThisIsInspired Magazine &#187; anchor tags</title>
	<atom:link href="http://www.thisisinspired.com/tag/anchor-tags/feed" rel="self" type="application/rss+xml" />
	<link>http://www.thisisinspired.com</link>
	<description>Dedicated to art, design, blogging &#38; inspiration</description>
	<lastBuildDate>Sat, 21 Jan 2012 16:07:20 +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>Quick: Dynamically Open External Links in a New Window</title>
		<link>http://www.thisisinspired.com/quick-dynamically-open-external-links-in-a-new-window</link>
		<comments>http://www.thisisinspired.com/quick-dynamically-open-external-links-in-a-new-window#comments</comments>
		<pubDate>Thu, 11 Feb 2010 14:58:21 +0000</pubDate>
		<dc:creator>Derek Land</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[anchor tags]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[new window]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.thisisinspired.com/?p=757</guid>
		<description><![CDATA[Since I began writing HTML ten years ago, I hated using target=&#8220;blank&#8221; in my markup. Coupled with the fact that if you&#8217;re using a strict DOCTYPE the target method is invalid anyway, I began looking for an easy way to open only external links in a new window (and I realize there are pros and <p>Thanks for reading This Is Inspired! Catch more inspiration online at <a href="http://www.thisisinspired.com">ThisIsInspired.com</a>  and share comments and feedback.</p>



Related posts:<ol><li><a href='http://www.thisisinspired.com/4-quick-easy-design-theory-tips' rel='bookmark' title='4 Quick &amp; Easy Design Theory Tips'>4 Quick &amp; Easy Design Theory Tips</a></li>
<li><a href='http://www.thisisinspired.com/1-fantastic-way-to-block-spam-on-a-wordpress-blog' rel='bookmark' title='Quick: 1 Fantastic Way to Block Spam on a WordPress Blog'>Quick: 1 Fantastic Way to Block Spam on a WordPress Blog</a></li>
<li><a href='http://www.thisisinspired.com/quick-awesome-time-lapse-movie-of-our-milky-way' rel='bookmark' title='Quick: Awesome Time-lapse Movie of Our Milky Way'>Quick: Awesome Time-lapse Movie of Our Milky Way</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Since I began writing HTML ten years ago, I hated using <code>target=&#8220;blank&#8221;</code> in my markup. Coupled with the fact that if you&#8217;re using a strict DOCTYPE the <code>target</code> method is invalid anyway, I began looking for an easy way to open only external links in a new window (and I realize there are pros and cons of doing this). Using this jQuery technique, each link is tested to check if it&#8217;s local or not, or alternatively in the second method only opening links in a new window if they are children of a given element.<span id="more-757"></span></p>
<p>*<em>Do make sure you import the jQuery library or else you&#8217;ll be left wondering why neither of these methods work.</em></p>
<h3>Method #1: All External Links</h3>
<p><strong>Opens all external links in a new browser window</strong><br />
Using this method, jQuery checks all link references to see if they are heading off to a local page (eg: hosted on the same domain) or if they are being sent on their merry way somewhere else.</p>
<p>To use this salubrious tidbit, find the  <code>script</code> block on your page, and paste in the follow snippet:</p>
<pre class="brush:javascript">
jQuery("a[href^='http:']").not("[href*='whatevs.com']").attr('target','_blank');
</pre>
<p>Make a note of the part that says &#8220;whatevs.om&#8221; and swap it out with your domain &ndash; thisisinspired.com or bing.com, (or .org, .net, .us, etc) for example.</p>
<p>This piece of jQuery will catch all anchor clicks and attach the behaviour otherwise achieved by <code>target=&#8220;_blank&#8221;</code>.</p>
<p>But what if you just need to open all the links in a certain area of a page in a new window? This may be useful in particular if you wish all links to open in the same <em>except</em> for those links that carry footnotes or references and are used in the midst of a lengthy article. In such cases, it might be to your audience&#8217;s best interests to open just those in a new window so they don&#8217;t lose their place. In this case, method #2 works best.</p>
<h3>Method #2: Only Specific Children Links</h3>
<p><strong>Open links in a new window only if they are children of a given section.</strong><br />
This is very, very similar to the one above, except that it doesn&#8217;t just batch all anchors together based on what domain they reference &ndash; it catches only the anchors within a certain element and opens them all in a new window.</p>
<p>Copy this snippet into the script area of your page:</p>
<pre class="brush:javascript">
jQuery("a[href^='http:']").attr('target','_blank');
</pre>
<p>&#8230;and note the <code>...$(&#8220;a[href...</code> area. Insert the ID or class of the parent element directly before the &#8220;a&#8221;, like so:</p>
<pre class="brush:javascript">
jQuery("#content a[href^='http:']").attr('target','_blank');
</pre>
<p>where <code>#content</code> is the ID name of the element whose anchors we want opened in a new window. For WordPress users, you might change this to <code>.post</code> to select all anchors within only the post itself.
<p>Thanks for reading This Is Inspired! Catch more inspiration online at <a href="http://www.thisisinspired.com">ThisIsInspired.com</a>  and share comments and feedback.</p>


<p>Related posts:<ol><li><a href='http://www.thisisinspired.com/4-quick-easy-design-theory-tips' rel='bookmark' title='4 Quick &amp; Easy Design Theory Tips'>4 Quick &amp; Easy Design Theory Tips</a></li>
<li><a href='http://www.thisisinspired.com/1-fantastic-way-to-block-spam-on-a-wordpress-blog' rel='bookmark' title='Quick: 1 Fantastic Way to Block Spam on a WordPress Blog'>Quick: 1 Fantastic Way to Block Spam on a WordPress Blog</a></li>
<li><a href='http://www.thisisinspired.com/quick-awesome-time-lapse-movie-of-our-milky-way' rel='bookmark' title='Quick: Awesome Time-lapse Movie of Our Milky Way'>Quick: Awesome Time-lapse Movie of Our Milky Way</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.thisisinspired.com/quick-dynamically-open-external-links-in-a-new-window/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.thisisinspired.com @ 2012-02-04 22:18:15 -->
