<?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>Think2Loud &#187; JavaScript</title> <atom:link href="http://think2loud.com/cat/javascript/feed/" rel="self" type="application/rss+xml" /><link>http://think2loud.com</link> <description>Random thoughts from a few geeks</description> <lastBuildDate>Wed, 04 Jan 2012 01:43:02 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>JSON vs. XML: What Should You Use?</title><link>http://think2loud.com/680-json-xml/</link> <comments>http://think2loud.com/680-json-xml/#comments</comments> <pubDate>Sun, 27 Dec 2009 21:02:54 +0000</pubDate> <dc:creator>Jared</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[json]]></category> <category><![CDATA[XML]]></category><guid isPermaLink="false">http://think2loud.com/?p=680</guid> <description><![CDATA[<p>Lots of people have asked me this question: which is better when loading data via an ajax request?  JSON is my favorite. I'm going to try and explain the benefits of JSON over XML. <a href="http://think2loud.com/680-json-xml/">Read More</a></p><p><a href="http://think2loud.com/680-json-xml/">JSON vs. XML: What Should You Use?</a></p>]]></description> <content:encoded><![CDATA[<p>From the start, JSON is already has a leg up on XML for one reason: it&#8217;s faster. To read XML you need to parse it, read the nodes, attributes, and child nodes in the XML document, and then use the data that you&#8217;ve found.</p><p>In jQuery the easiest way to do that is to use the built-in ajax functions to call the XML and use the each function to loop through all the nodes. The each function is nice, but is much much slower than a for loop. Just imagine what happens when we have an XML document with multiple levels of nested nodes you need to get at. You end up with multiple nested $.each functions and without much trying, you end up with a script that crawls. With JSON it&#8217;s easy to get at the data since its already native javascript. No parsers or proxies necessary&#8211;all you need to do is loop through the data, fast and simple. That&#8217;s one point for JSON.</p><p>There are aspects of XML that people point to as reasons to use it.  First, XML is both human and machine readable. It is nice to see what data is being returned just by viewing the source, but that problem is solved by having good documentation, including an example of the JSON that will be returned. Also, being a front-end developer, I spend a lot of my time reading javascript anyway.  I find it just as easy to read as XML, it&#8217;s just different.</p><p>Another good reason to use XML is that it&#8217;s widely available.  Lots of websites offer APIs to get at their public (and sometimes private) data, and I usually find the returned format of these APIs are often either XML or JSON.  However since XML has been around longer than JSON, there is simply more XML out there.</p><p>Sometimes you might find yourself in a situation where you don&#8217;t have JSON as an option.  So do you submit to the API gods and slow down your site and just use the XML?  Why do that when you can write the API yourself!  This is where some server side skills come in handy.  It&#8217;s super easy to load an XML document via PHP and print out the data in whatever format you need it to be in.</p><p>So in conclusion, you should be using JSON every chance you get.</p><p><a href="http://think2loud.com/680-json-xml/">JSON vs. XML: What Should You Use?</a></p>]]></content:encoded> <wfw:commentRss>http://think2loud.com/680-json-xml/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Using Advanced Segments in Google Analytics to Separate Outgoing Links and Downloads from Pageviews</title><link>http://think2loud.com/365-using-advanced-segments-in-google-analytics-to-separate-outgoing-links-and-downloads-from-pageviews/</link> <comments>http://think2loud.com/365-using-advanced-segments-in-google-analytics-to-separate-outgoing-links-and-downloads-from-pageviews/#comments</comments> <pubDate>Fri, 10 Apr 2009 03:28:40 +0000</pubDate> <dc:creator>Josh</dc:creator> <category><![CDATA[JavaScript]]></category><guid isPermaLink="false">http://think2loud.com/?p=365</guid> <description><![CDATA[<p>If you're like me, you installed the <a href="http://plugins.spiralwebconsulting.com/analyticator.html">Google Analyticator</a> plugin for your blog or added some other javascript so you could track what outgoing links where clicked. You will have extra pageviews showing in your <a href="http://www.google.com/analytics/">Google Analytics</a> account that are what I call "ghost pages." These pages don't really exist--they are just place holders for the clicks to other sites or your downloads. To get a more accurate number of pageviews, you can use Advanced Segments to create a new segment that will remove these ghost pages. So go log into your <a href="http://www.google.com/analytics/">Google Analytics</a> account and let's get started. <a href="http://think2loud.com/365-using-advanced-segments-in-google-analytics-to-separate-outgoing-links-and-downloads-from-pageviews/">Read More</a></p><p><a href="http://think2loud.com/365-using-advanced-segments-in-google-analytics-to-separate-outgoing-links-and-downloads-from-pageviews/">Using Advanced Segments in Google Analytics to Separate Outgoing Links and Downloads from Pageviews</a></p>]]></description> <content:encoded><![CDATA[<h2>Creating the Segment</h2><ol><li>Make your way to the dashboard for the site you are tracking.</li><li><p>When you reach the dashboard, you will see a settings section on the left. Click the Advanced Segment(beta) link.</p><p><img src="http://zippy.think2loud.com/wp-content/uploads/2009/04/picture-15.png" alt="Dashboard" title="Dashboard" width="437" height="394" class="alignnone size-full wp-image-372" /></li><li><p>There will now be a link in the upper right that says &#8220;Create new custom segment.&#8221; Click that to start your new segment. You should now be on a page that looks like the one below.</p><p><img src="http://zippy.think2loud.com/wp-content/uploads/2009/04/picture-16.png" alt="Create Segment" title="Create Segment" width="490" height="328" class="alignnone size-full wp-image-368" /></li><li>Under the Dimensions header on the left it&#8217;s probably green. There is a section for content. Pop that open to reveal a list of options.</li><li>Drag the Page box onto the box on the right that says &#8220;dimension or metric.&#8221; Then select &#8220;Does not start with&#8221; from the drop down that appears under the Condition header. Put &#8220;/outgoing&#8221; in the Value text area. This gives you a filter that will get all pages that do not start with &#8220;/outgoing&#8221;</li><li>Now you&#8217;ll need to make another filter in this same segment that also removes the downloads. Click the &#8216;Add &#8220;and&#8221; statement&#8217; link.</li><li>You will now have another &#8220;dimension or metric&#8221; box. You will want to repeat step 5 but change &#8220;/outgoing&#8221; to &#8220;/download&#8221; or whatever you use to mark your downloads.</li><li>Test your segment with the test segment button on the bottom right side of the page.</li><li>Now give your segment a name and hit &#8220;Create.&#8221; I used &#8220;- outgoing/download&#8221; as a name.</li></ol><p>The finished segment should look like this before you hit create.</p><p><a href="http://zippy.think2loud.com/wp-content/uploads/2009/04/picture-18.png" rel="lightbox[365]"><img src="http://zippy.think2loud.com/wp-content/uploads/2009/04/picture-18-300x215.png" alt="Finished Segment" title="Finished Segment" width="300" height="215" class="alignnone size-medium wp-image-374" /></a></p><h2>Using the Segment</h2><ol><li>Make your way back to the dashboard for your site.</li><li><p>Directly above the date picker on the right in the gray menu box there is a drop down labeled Advanced Segments. Click the drop down to open the Advanced Segments options.</p><p><img src="http://zippy.think2loud.com/wp-content/uploads/2009/04/picture-19.png" alt="Select Segment" title="Select Segment" width="318" height="245" class="alignnone size-full wp-image-377" /></li><li><p>Under custom segments, click the check box next to your new segment you just created. Also leave the all visits default segment checked if you would like to see your unfiltered results.</p><p><img src="http://zippy.think2loud.com/wp-content/uploads/2009/04/picture-23-300x144.png" alt="Segment Options" title="Segment Options" width="300" height="144" class="alignnone size-medium wp-image-379" /></li><li>Hit &#8220;Apply&#8221; and that is it.</li></ol><p>Once all this is done you will be able to quickly find a more accurate count of pageviews.</p><p><img src="http://zippy.think2loud.com/wp-content/uploads/2009/04/picture-24.png" alt="Site Usage" title="Site Usage" width="308" height="235" class="alignnone size-full wp-image-381" /></p><p><a href="http://think2loud.com/365-using-advanced-segments-in-google-analytics-to-separate-outgoing-links-and-downloads-from-pageviews/">Using Advanced Segments in Google Analytics to Separate Outgoing Links and Downloads from Pageviews</a></p>]]></content:encoded> <wfw:commentRss>http://think2loud.com/365-using-advanced-segments-in-google-analytics-to-separate-outgoing-links-and-downloads-from-pageviews/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Using jQuery and XML to Populate a Drop-Down Box</title><link>http://think2loud.com/288-using-jquery-and-xml-to-populate-a-drop-down-box/</link> <comments>http://think2loud.com/288-using-jquery-and-xml-to-populate-a-drop-down-box/#comments</comments> <pubDate>Tue, 10 Mar 2009 00:30:41 +0000</pubDate> <dc:creator>Josh</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[XML]]></category><guid isPermaLink="false">http://think2loud.com/?p=288</guid> <description><![CDATA[<p>Building on the post <a href="/reading-xml-with-jquery/">Reading XML with jQuery</a>, I have modified the success function to parse the XML data and load it into a drop-down box. You can get the demo files from Reading XML with jQuery <a href="/examples/XML.zip">here</a>. Once you download and unzip the demo files, open the index.html in your favorite editor. Then remove all the HTML between the body tag and also all the jQuery in the success function. I also changed the page title to "Using jQuery and XML to Populate a Drop-Down Box Demo." <a href="http://think2loud.com/288-using-jquery-and-xml-to-populate-a-drop-down-box/">Read More</a></p><p><a href="http://think2loud.com/288-using-jquery-and-xml-to-populate-a-drop-down-box/">Using jQuery and XML to Populate a Drop-Down Box</a></p>]]></description> <content:encoded><![CDATA[<p><a target="_blank" href="/examples/jquery-dropdown-xml/jquery-dropdown-xml.zip" class="button">Source</a> <a target="_blank" href="/examples/jquery-dropdown-xml/" class="button">Demo</a> <a target="_blank" class="button" href="/examples/XML.zip">Reading XML with jQuery Source</a></p><p><span id="more-288"></span></p><p>You&#8217;ll now have an index.html file that looks like this:</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;all&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Using jQuery and XML to populate a drop-down box demo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
     	$(document).ready(function(){
			$.ajax({
				type: &quot;GET&quot;,
				url: &quot;sites.xml&quot;,
				dataType: &quot;xml&quot;,
				success: function(xml) {
&nbsp;
				}
			});
		});
     <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;page-wrap&quot;</span>&gt;</span>
    	<span style="color: #808080; font-style: italic;">&lt;!-- all tags removed --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div><p>Next you&#8217;ll need a simple XML file to load.</p><p>Here is the one that I used : <a target="_blank" href="/examples/jquery-dropdown-xml/dropdown.xml">dropdown.xml</a></p><div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;iso-8859-1&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dropdown<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;menuitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>first set<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;values<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>option a<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>option b<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/values<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/menuitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;menuitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>second set<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;values<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>option 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>option 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/values<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/menuitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;menuitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>third set<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;values<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>option 1a<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>option 2b<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/values<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/menuitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dropdown<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><p>Now that you&#8217;ve created your XML, add a form with a select box to the HTML page. I simply replaced everything within the body tag from our index.html from the previous article.</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mySelect&quot;</span>&gt;</span>
              <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>loading<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div><p>Once the XML is ready, jump back into the index.html file. You&#8217;ll need to update the jQuery Ajax call to get the new XML document. To do this, simply change the url to your new document.</p><p>old:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;sites.xml&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;xml&quot;</span><span style="color: #339933;">,</span>
	success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>new:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;dropdown.xml&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;xml&quot;</span><span style="color: #339933;">,</span>
	success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>With the Ajax call in place, you need to tell it what to do when it loads the XML in the success function. Start by getting the select tag with jQuery and storing it in a variable for later use. The select tag you are looking for has an id of mySelect.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> select <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mySelect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Next, loop through all of the menuitem nodes in the XML with a jQuery each function.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'menuitem'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Inside the each function, you will get the title of your menuitem. Create an option tag as a header for the menuitem, and then create another jQuery each function to get all the possible values that go with the current menuitem.</p><p>The first thing you&#8217;ll want to do within the each function for the menuitem is get the title and append it to your select.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
select.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;option/&gt;&lt;option class='ddheader'&gt;&quot;</span><span style="color: #339933;">+</span>title<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/option&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>There is a empty option tag in the code to get a space above the header, that way the drop down will be easier for the user to read. Add a class of ddheader to the option tag so in browser like firefox you can make the header bold.</p><p>With the header now inserted into the select, you&#8217;ll now need to create the options that will be under that header. To do this, use another jQuery each function, looking for all the value nodes that are in the menuitem node. Within this each you will get the text in the value node and then append it to the select tag as an option with a class of ddindent. The ddindent class is used to push these items to the right a bit so they are easy to follow.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> value <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	select.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;option class='ddindent' value='&quot;</span><span style="color: #339933;">+</span> value <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&gt;&quot;</span><span style="color: #339933;">+</span>value<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/option&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>That is just about everything, there&#8217;s only one more thing. At the end of the success function, change the option tag you hard coded in the index.html file that said &#8220;loading&#8221; to now say &#8220;please make a selection.&#8221; Make sure that it&#8217;s selected to start with by giving it the selected attribute. Because the option tag is the first child of the select tag, you can use the children function with the optional parameter of &#8220;:first&#8221;. This will return only the first child of the select tag.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">select.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:first&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;please make a selection&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;selected&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>You should now have a functional drop-down box loaded with XML via jQuery.</p><p><a target="_blank" href="/examples/jquery-dropdown-xml/jquery-dropdown-xml.zip" class="button">Source</a> <a target="_blank" class="button" href="/examples/jquery-dropdown-xml/">Demo</a> <a target="_blank" href="/examples/XML.zip" class="button">Reading XML with jQuery Source</a></p><p><a href="http://think2loud.com/288-using-jquery-and-xml-to-populate-a-drop-down-box/">Using jQuery and XML to Populate a Drop-Down Box</a></p>]]></content:encoded> <wfw:commentRss>http://think2loud.com/288-using-jquery-and-xml-to-populate-a-drop-down-box/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> <item><title>Add Scroll Bars to Full Browser Flash with a Simple jQuery Plugin</title><link>http://think2loud.com/268-add-scroll-bars-to-full-browser-flash-with-a-simple-jquery-plugin/</link> <comments>http://think2loud.com/268-add-scroll-bars-to-full-browser-flash-with-a-simple-jquery-plugin/#comments</comments> <pubDate>Wed, 10 Sep 2008 03:09:36 +0000</pubDate> <dc:creator>Josh</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Flash]]></category><guid isPermaLink="false">http://www.think2loud.com/?p=268</guid> <description><![CDATA[<p>Got a great Flash site? Can it be used by someone with low resolution? This plugin offers an easy way to keep your full browser Flash from getting too small. <a href="http://think2loud.com/268-add-scroll-bars-to-full-browser-flash-with-a-simple-jquery-plugin/">Read More</a></p><p><a href="http://think2loud.com/268-add-scroll-bars-to-full-browser-flash-with-a-simple-jquery-plugin/">Add Scroll Bars to Full Browser Flash with a Simple jQuery Plugin</a></p>]]></description> <content:encoded><![CDATA[<p><a target="_blank" class="button" href="http://www.think2loud.com/examples/flashresize.zip">.zip</a> <a target="_blank" class="button" href="http://www.think2loud.com/examples/flashresize/jquery.flashResize.js">.js only</a> <a target="_blank" class="button" href="http://www.think2loud.com/examples/flashresize/">Demo</a></p><p><span id="more-268"></span><br /> The first thing you need to do is get <a target="_blank" href="http://www.jquery.com">jQuery</a> set up and running. Once you have that done, I recommend the <a target="_blank" href="http://jquery.lukelutman.com/plugins/flash">jQuery Flash Plugin</a> for embedding your Flash movies, but you can use any method you like. Now you need to download and include the <a target="_blank" href="http://www.think2loud.com/examples/flashresize/jquery.flashResize.js">jQuery FlashResize Plugin</a>.</p><p>With the plugin included and ready to use, we need to get it running. You will need to have an element to use as your placeholder. The body tag can be used, but I always use a container element, usually a div.<br /> <br/></p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
     <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flash-scroll&quot;</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Html to be replaced by 100% Flash.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
     <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span></pre></div></div><p>With the HTML set up for the scroll bars, you simply need to add the call to the FlashResize plugin in the document.ready function. The plugin only has two parameters <em>minWidth</em> and <em>minHeight</em>. If you don&#8217;t specify a value, then the Flash container is set to 100% and no scroll bar is added.</p><p>So just set the parameters to your minimum values and that&#8217;s it. As you can see below, the Flash has been set to a minimum of 800 by 750.<br /> <br/></p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#flash-scroll'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">flashResize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  		minWidth<span style="color: #339933;">:</span> <span style="color: #CC0000;">800</span><span style="color: #339933;">,</span>
  		minHeight<span style="color: #339933;">:</span> <span style="color: #CC0000;">750</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>If you would like to see this plugin in action, check out the demo.</p><p><a target="_blank" class="button" href="http://www.think2loud.com/examples/flashresize.zip">.zip</a> <a target="_blank" class="button" href="http://www.think2loud.com/examples/flashresize/jquery.flashResize.js">.js only</a> <a target="_blank" class="button" href="http://www.think2loud.com/examples/flashresize/">Demo</a></p><p><a href="http://think2loud.com/268-add-scroll-bars-to-full-browser-flash-with-a-simple-jquery-plugin/">Add Scroll Bars to Full Browser Flash with a Simple jQuery Plugin</a></p>]]></content:encoded> <wfw:commentRss>http://think2loud.com/268-add-scroll-bars-to-full-browser-flash-with-a-simple-jquery-plugin/feed/</wfw:commentRss> <slash:comments>36</slash:comments> </item> <item><title>Reading XML with jQuery</title><link>http://think2loud.com/224-reading-xml-with-jquery/</link> <comments>http://think2loud.com/224-reading-xml-with-jquery/#comments</comments> <pubDate>Sat, 06 Sep 2008 17:00:00 +0000</pubDate> <dc:creator>Jared</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[XML]]></category><guid isPermaLink="false">http://www.think2loud.com/?p=224</guid> <description><![CDATA[<p>Welcome to my first of many articles for Think2Loud! Today I thought I'd start with something simple that will lead into several other topics. So here we go, head first into reading XML with <a href="http://jquery.com/" >jQuery</a>. <a href="http://think2loud.com/224-reading-xml-with-jquery/">Read More</a></p><p><a href="http://think2loud.com/224-reading-xml-with-jquery/">Reading XML with jQuery</a></p>]]></description> <content:encoded><![CDATA[<p>The first step is making sure you have jQuery included on your page.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div><p>Second, you should check the XML file you are going to read and make sure it&#8217;s free of errors. If you are unfamiliar with XML synatax, check out the W3School&#8217;s <a target="_blank" href="http://www.w3schools.com/Xml/xml_syntax.asp" >rules on XML syntax</a>. The file I&#8217;m using for this example is just a listing of some Web sites I enjoy.</p><p>Finally, you just need to tell jQuery to read the file and print out the contents. Start by adding the document.ready function to the page.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p><span id="more-224"></span><br /> Within the document.ready we start a jQuery ajax request to read the XML file. The ajax request takes four parameters: file type, url, dataType, and success. You&#8217;ll see below how these are set to read a file. The important thing to notice is the success parameter. We set it to a function that takes the data the request gets from the XML file.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;sites.xml&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;xml&quot;</span><span style="color: #339933;">,</span>
	success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>This is where the fun part comes in. Now that we are reading the XML, we need to find the data written within it and do something with it. We start by reading the returned data and using the find method to get all the nodes that match the text we supply (in this case, &#8220;site&#8221;), and then use the each function to loop through what the find function give to us.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'site'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>All that&#8217;s left is to get the data from that node and print it out. Do this by using the attr function, and the find function to get the text and any attributes on the nodes.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'url'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;items&quot; id=&quot;link_'</span><span style="color: #339933;">+</span>id<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a href=&quot;'</span><span style="color: #339933;">+</span>url<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span><span style="color: #339933;">+</span>title<span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#page-wrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Your final code should look something like this:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
		url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;sites.xml&quot;</span><span style="color: #339933;">,</span>
		dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;xml&quot;</span><span style="color: #339933;">,</span>
		success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'site'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003366; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'url'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;items&quot; id=&quot;link_'</span><span style="color: #339933;">+</span>id<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a href=&quot;'</span><span style="color: #339933;">+</span>url<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span><span style="color: #339933;">+</span>title<span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#page-wrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'desc'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #003366; font-weight: bold;">var</span> brief <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'brief'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #003366; font-weight: bold;">var</span> long <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'long'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;brief&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>brief<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#link_'</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;long&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>long<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#link_'</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>That&#8217;s all it takes to read XML with jQuery. Feel free to check out the <a target="_blank" href="http://www.think2loud.com/examples/xml/" >demo</a> and download the <a target="_blank" href="http://www.think2loud.com/examples/XML.zip">source code</a>.</p><p><a href="http://think2loud.com/224-reading-xml-with-jquery/">Reading XML with jQuery</a></p>]]></content:encoded> <wfw:commentRss>http://think2loud.com/224-reading-xml-with-jquery/feed/</wfw:commentRss> <slash:comments>45</slash:comments> </item> <item><title>Build an Unsupported Browser Warning with jQuery</title><link>http://think2loud.com/147-build-an-unsupported-browser-warning-with-jquery/</link> <comments>http://think2loud.com/147-build-an-unsupported-browser-warning-with-jquery/#comments</comments> <pubDate>Wed, 03 Sep 2008 20:54:58 +0000</pubDate> <dc:creator>Josh</dc:creator> <category><![CDATA[JavaScript]]></category><guid isPermaLink="false">http://www.think2loud.com/?p=147</guid> <description><![CDATA[<p>Over at <a href="http://www.css-tricks.com">CSS-tricks</a> there's an article about blocking Internet Explorer 6. If the <a href="http://css-tricks.com/ie-6-blocker-script/">IE 6 Blocker Script</a> is a little too extreme for you, check out what I use on client web sites. <a href="http://think2loud.com/147-build-an-unsupported-browser-warning-with-jquery/">Read More</a></p><p><a href="http://think2loud.com/147-build-an-unsupported-browser-warning-with-jquery/">Build an Unsupported Browser Warning with jQuery</a></p>]]></description> <content:encoded><![CDATA[<p>Trying to get someone to upgrade, without being overly aggravating, can be tough. This script accomplishes this by adding a warning box across the top of the site with an option to hide the message. The script uses cookies, so if someone hides the warning it will not come back until they restart their browser. This way, even with an unsupported browser, they can remove the warning and use your site as they wish.</p><p><a href="http://zippy.think2loud.com/wp-content/uploads/2008/09/badbrowser.jpg" rel="lightbox[147]"><img class="alignnone size-full wp-image-207" title="badbrowser" src="http://zippy.think2loud.com/wp-content/uploads/2008/09/badbrowser.jpg" alt="" width="500" height="217" /></a></p><p><a target="_blank" class="button" href="http://www.think2loud.com/examples/badbrowser.zip">Source</a> <a target="_blank" class="button" href="http://www.think2loud.com/examples/badbrowser/">Demo</a> (Firefox is also unsupported for the Demo)</p><h2>Initial Setup</h2><p>To get started you need to include jQuery and the badBrowser script in the header. The script does the browser detection. This allows for screening of multiple browsers if you like. I just set it up for IE 6 and below.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery-1.2.6.min.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery.badBrowser.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div><h2>So whats in the badBrowser.js file?</h2><p>The first thing you will see is the badBrowser function. This function checks for the browsers that you want to show the warning on. It uses jQuery&#8217;s built-in utilities for browser checking. The function returns true if it&#8217;s an unsupported browser and returns false if it&#8217;s not.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> badBrowser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span>.<span style="color: #660066;">msie</span> <span style="color: #339933;">&amp;&amp;</span> parseInt<span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span>.<span style="color: #660066;">version</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">6</span><span style="color: #009900;">&#41;</span>
             <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>Next we have our functions to Get and Set our cookie. The Set function creates a cookie with the name and value of what you pass it. The Get function returns the value of a cookie based on the name you pass into the function. If there is no cookie with that name, it returns an empty string.  I am not going to go into the finer details of these functions, but if you&#8217;d like to read more about JavaScript cookies check out: <a target="_blank" href="http://www.quirksmode.org/js/cookies.html">http://www.quirksmode.org/js/cookies.html</a></p><p>The Set Function:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> setBadBrowser<span style="color: #009900;">&#40;</span>c_name<span style="color: #339933;">,</span>value<span style="color: #339933;">,</span>expiredays<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> exdate<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	exdate.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span>exdate.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>expiredays<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	document.<span style="color: #660066;">cookie</span><span style="color: #339933;">=</span>c_name<span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;=&quot;</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
        <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>expiredays<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;;expires=&quot;</span> <span style="color: #339933;">+</span>
        exdate.<span style="color: #660066;">toGMTString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>The Get Function:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> getBadBrowser<span style="color: #009900;">&#40;</span>c_name<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span>.<span style="color: #660066;">length</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   c_start<span style="color: #339933;">=</span>document.<span style="color: #660066;">cookie</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>c_name <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c_start<span style="color: #339933;">!=-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    c_start<span style="color: #339933;">=</span>c_start <span style="color: #339933;">+</span> c_name.<span style="color: #660066;">length</span><span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    c_end<span style="color: #339933;">=</span>document.<span style="color: #660066;">cookie</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;;&quot;</span><span style="color: #339933;">,</span>c_start<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c_end<span style="color: #339933;">==-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> c_end<span style="color: #339933;">=</span>document.<span style="color: #660066;">cookie</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> unescape<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span>.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>c_start<span style="color: #339933;">,</span>c_end<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>Now with our helper functions all set up we can do some real work. We&#8217;re going to have an if statement that calls the browser check and also checks to see if our cookie has been set.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>badBrowser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> getBadBrowser<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'browserWarning'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #3366CC;">'seen'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div><p>Inside the if statement we are going to pre-pend our warning box to the top of our page and set some CSS for it.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div id='browserWarning'&gt;You are using an unsupported browser. Please switch to &lt;a href='http://getfirefox.com'&gt;FireFox&lt;/a&gt;, &lt;a href='http://www.opera.com/download/'&gt;Opera&lt;/a&gt;, &lt;a href='http://www.apple.com/safari/'&gt;Safari&lt;/a&gt; or &lt;a href='http://www.microsoft.com/windows/downloads/ie/getitnow.mspx'&gt;Internet Explorer 7&lt;/a&gt;. Thanks!   [&lt;a id='warningClose' href='#'&gt;close&lt;/a&gt;]&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	backgroundColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#fcfdde'</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">'width'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'100%'</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">'border-top'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'solid 1px #000'</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">'border-bottom'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'solid 1px #000'</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">'text-align'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'center'</span><span style="color: #339933;">,</span>
	padding<span style="color: #339933;">:</span><span style="color: #3366CC;">'5px 0px 5px 0px'</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
	.<span style="color: #660066;">prependTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Just one step left. We need to set up our onClick function for our close button. So with the jQuery click function we tell our button to Set our cookie and then hide the warning box.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#warningClose'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	setBadBrowser<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'browserWarning'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'seen'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#browserWarning'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>That pretty much covers the whole setup. Feel free to modify this in any way you see fit.</p><p><a target="_blank" class="button" href="http://www.think2loud.com/examples/badbrowser.zip">Source</a> <a target="_blank" class="button" href="http://www.think2loud.com/examples/badbrowser/">Demo</a> (Firefox is also unsupported for the Demo)</p><p><a href="http://think2loud.com/147-build-an-unsupported-browser-warning-with-jquery/">Build an Unsupported Browser Warning with jQuery</a></p>]]></content:encoded> <wfw:commentRss>http://think2loud.com/147-build-an-unsupported-browser-warning-with-jquery/feed/</wfw:commentRss> <slash:comments>29</slash:comments> </item> <item><title>Use jQuery with Google Analytics to Track Clicks on Outgoing Links From Your Site.</title><link>http://think2loud.com/105-use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/</link> <comments>http://think2loud.com/105-use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/#comments</comments> <pubDate>Wed, 27 Aug 2008 02:32:52 +0000</pubDate> <dc:creator>Josh</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Google Analytics]]></category><guid isPermaLink="false">http://www.think2loud.com/?p=105</guid> <description><![CDATA[<p>So you have a nice site or blog with lots of links to other places. Wouldn't it be nice to use the power built into Google Analytics to track those links, without having to add the necessary JavaScript to every link? Here is a very easy way: Add outbound link tracking to a new or existing site. Provided that your links to other sites have the REL attribute set, you can track them very easily with some help from jQuery. <a href="http://think2loud.com/105-use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/">Read More</a></p><p><a href="http://think2loud.com/105-use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/">Use jQuery with Google Analytics to Track Clicks on Outgoing Links From Your Site.</a></p>]]></description> <content:encoded><![CDATA[<h2>1. Download jQuery and install Goolge Analytics.</h2><p>Go to <a target="_blank" href="http://www.jquery.com" target="_blank">jQuery.com</a> and get the latest version. Then add the script include into the header of your site.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery-1.2.6.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div><p>Now go to <a target="_blank" href="http://www.google.com/analytics" target="_blank">Google Analytics</a>. Set up an account and follow the directions to get tracking running. Go ahead, do it now, I&#8217;ll wait. You should now have some script on your site that looks like:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> gaJsHost <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;https:&quot;</span> <span style="color: #339933;">==</span> document.<span style="color: #660066;">location</span>.<span style="color: #660066;">protocol</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;https://ssl.&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span>unescape<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;%3Cscript src='&quot;</span> <span style="color: #339933;">+</span> gaJsHost <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;google-analytics.com/ga.js'
type='text/javascript'%3E%3C/script%3E&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> pageTracker <span style="color: #339933;">=</span> _gat._getTracker<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;YOUR ACCOUNT NUMBER HERE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> pageTracker._trackPageview<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><h2>2. Add the jQuery to start tracking links.</h2><p>In the head section of your page, you will need to add a few lines of JavaScript. You will need to setup the jQuery .ready function and add the code to that.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Next use a jQuery selector to select all a tags on the page with a rel=&#8221;external&#8221;. To do this, pass jQuery the a tag element with the attribute selector option.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[rel*='external']&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div><p>with this we add a click function to our jQuery object.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[rel*='external']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>With the last part we put in the function call to the Google Analytics code and we pass it the href that our a tag is pointing to.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">pageTracker._trackPageview<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/outgoing/'</span><span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>This code makes the call to Google Analytics and passes a page path of &#8220;/outgoing/&#8221; and the url of where the click was headed. In your Google Analytics under content, you will see pages that start with &#8220;/outgoing/&#8221;. These are clicks that took people off your site. See below for how it looks in Google Analytics.</p><p><a href="http://zippy.think2loud.com/wp-content/uploads/2008/08/outgoing.png" rel="lightbox[105]"><img class="alignnone size-full wp-image-121" title="outgoing" src="http://zippy.think2loud.com/wp-content/uploads/2008/08/outgoing.png" alt="" width="500" height="204" /></a></p><p><a href="http://think2loud.com/105-use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/">Use jQuery with Google Analytics to Track Clicks on Outgoing Links From Your Site.</a></p>]]></content:encoded> <wfw:commentRss>http://think2loud.com/105-use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/feed/</wfw:commentRss> <slash:comments>76</slash:comments> </item> <item><title>Adding Twitter to Your Web Site with JavaScript</title><link>http://think2loud.com/24-adding-twitter-to-your-website-with-javascript/</link> <comments>http://think2loud.com/24-adding-twitter-to-your-website-with-javascript/#comments</comments> <pubDate>Sat, 16 Aug 2008 04:06:28 +0000</pubDate> <dc:creator>Josh</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Ajax]]></category> <category><![CDATA[Twitter]]></category><guid isPermaLink="false">http://www.think2loud.com/?p=24</guid> <description><![CDATA[<p>Today at work we needed to pull our Twitter feed into our site. Not wanting to have to deal with the Twitter feed in back-end code, we decided to try out some already-written JavaScript setups for doing what we needed. <a href="http://think2loud.com/24-adding-twitter-to-your-website-with-javascript/">Read More</a></p><p><a href="http://think2loud.com/24-adding-twitter-to-your-website-with-javascript/">Adding Twitter to Your Web Site with JavaScript</a></p>]]></description> <content:encoded><![CDATA[<p>After testing out a few different ones, we finally settled on <a target="_blank" href="http://remysharp.com/2007/05/18/add-twitter-to-your-blog-step-by-step/">twitter.js</a> written by Remy Sharp.</p><p>Twitter.js seems to have the most flexibility and had the options we were looking for. It also seems to load a lot more consistently than the others (although I think that is more of a network issue at work). Below is a list of all the ones we tried&#8211;they were all great. If you are looking to add your Tweets to you web site, below are some great places to start.</p><ul><li><a target="_blank" href="http://remysharp.com/2007/05/18/add-twitter-to-your-blog-step-by-step/">Twitter.js</a> by Remy Sharp. Features a simple, clean setup that is easy to use and has a lot of options that can be set.</li><li><a target="_blank" href="http://tweet.seaofclouds.com/">Tweet!</a> by seaofclouds. This is a Jquery plugin and seemed to work very well. It didn&#8217;t do exactly what we were looking for, but since this is a Jquery plugin, it was hard to pass up.</li><li><a target="_blank" href="http://www.addtweets.com/">addTweets</a> This is great if you just lwant to add Tweets to you site with no work. You enter your Twitter info and addTweets generates all the code for you. You have up to 10 Tweets on your page with just a copy and a paste.</li></ul><p><a href="http://think2loud.com/24-adding-twitter-to-your-website-with-javascript/">Adding Twitter to Your Web Site with JavaScript</a></p>]]></content:encoded> <wfw:commentRss>http://think2loud.com/24-adding-twitter-to-your-website-with-javascript/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Served from: think2loud.com @ 2012-02-03 22:01:03 by W3 Total Cache -->
