<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: JavaScript Query String</title>
	<atom:link href="http://prettycode.org/2009/04/21/javascript-query-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://prettycode.org/2009/04/21/javascript-query-string/</link>
	<description>foreach(bill) paywith(skill);</description>
	<lastBuildDate>Fri, 05 Mar 2010 01:42:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chris</title>
		<link>http://prettycode.org/2009/04/21/javascript-query-string/comment-page-1/#comment-12</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 24 Apr 2009 17:54:38 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=145#comment-12</guid>
		<description>@Miron: I don&#039;t think the GetQuerystringParam() you&#039;ve shown is a bad tool. My concern with using it is that it&#039;s easily abused &lt;i&gt;because it&#039;s a function&lt;/i&gt;. What if another developer is maintaining the app. and wants to grab another value in the query string? They&#039;ll likely just call the same function you used. The consequence isn&#039;t performance (as you say, it&#039;s negligible). Code should be written with reuse in mind, and defensively against misuse&#8212;as a practice. A function encourages repetitious, procedural, imperative design, while an object encourages encapsulation, separation of concerns, and adherence to DRY. The consequence (at least in my mind) is that such a function has greater potential to encourage sloppy code.

I think what is probably a great idea is replacing the name/value parsing logic in my code with the regular expressions you&#039;re using if the regex is bulletproof. :)</description>
		<content:encoded><![CDATA[<p>@Miron: I don&#8217;t think the GetQuerystringParam() you&#8217;ve shown is a bad tool. My concern with using it is that it&#8217;s easily abused <i>because it&#8217;s a function</i>. What if another developer is maintaining the app. and wants to grab another value in the query string? They&#8217;ll likely just call the same function you used. The consequence isn&#8217;t performance (as you say, it&#8217;s negligible). Code should be written with reuse in mind, and defensively against misuse&mdash;as a practice. A function encourages repetitious, procedural, imperative design, while an object encourages encapsulation, separation of concerns, and adherence to DRY. The consequence (at least in my mind) is that such a function has greater potential to encourage sloppy code.</p>
<p>I think what is probably a great idea is replacing the name/value parsing logic in my code with the regular expressions you&#8217;re using if the regex is bulletproof. <img src='http://prettycode.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miron</title>
		<link>http://prettycode.org/2009/04/21/javascript-query-string/comment-page-1/#comment-11</link>
		<dc:creator>Miron</dc:creator>
		<pubDate>Fri, 24 Apr 2009 09:54:30 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=145#comment-11</guid>
		<description>In other hand, why should you parse all the query string parameters when you need only one?
Also, you are talking about client side code and regular expression over not so long string... The performance impact is negligible.</description>
		<content:encoded><![CDATA[<p>In other hand, why should you parse all the query string parameters when you need only one?<br />
Also, you are talking about client side code and regular expression over not so long string&#8230; The performance impact is negligible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://prettycode.org/2009/04/21/javascript-query-string/comment-page-1/#comment-10</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 23 Apr 2009 03:38:01 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=145#comment-10</guid>
		<description>@Garry: Good point. In response, I&#039;ve changed the script to avoid manually rebuilding the decoded query string toString() returns, and instead, the decoded &lt;c&gt;location.search&lt;/c&gt; value is returned by toString(). Thanks again!</description>
		<content:encoded><![CDATA[<p>@Garry: Good point. In response, I&#8217;ve changed the script to avoid manually rebuilding the decoded query string toString() returns, and instead, the decoded <c>location.search</c> value is returned by toString(). Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://prettycode.org/2009/04/21/javascript-query-string/comment-page-1/#comment-9</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 23 Apr 2009 03:34:53 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=145#comment-9</guid>
		<description>@Miron: While that works, every time GetQuerystringParam() is invoked, the URL has mutiple regular expressions matched against it, which is bad practice. The URL should be broken down into a collection or examined for a name/value pair &lt;i&gt;once&lt;/i&gt;; not every time a query string parameter value is needed.</description>
		<content:encoded><![CDATA[<p>@Miron: While that works, every time GetQuerystringParam() is invoked, the URL has mutiple regular expressions matched against it, which is bad practice. The URL should be broken down into a collection or examined for a name/value pair <i>once</i>; not every time a query string parameter value is needed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miron</title>
		<link>http://prettycode.org/2009/04/21/javascript-query-string/comment-page-1/#comment-8</link>
		<dc:creator>Miron</dc:creator>
		<pubDate>Wed, 22 Apr 2009 19:57:18 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=145#comment-8</guid>
		<description>You can use this method:

&lt;pre lang=&quot;javascript&quot;&gt;
//
// Get query string parameter
//
function GetQuerystringParam(name, url) {
    name = name.replace(/[\[]/, &quot;\\\[&quot;).replace(/[\]]/, &quot;\\\]&quot;);
    var regexS = &quot;[\\?&amp;]&quot; + name + &quot;=([^&amp;#]*)&quot;;
    var regex = new RegExp(regexS);
    if (typeof (url) == &#039;undefined&#039;) url = window.location.href;
    var results = regex.exec(url);
    if (results == null)
        return &quot;&quot;;
    else
        return results[1];
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>You can use this method:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: green; font-style: italic;">//</span>
<span style="color: green; font-style: italic;">// Get query string parameter</span>
<span style="color: green; font-style: italic;">//</span>
<span style="color: purple;">function</span> GetQuerystringParam<span style="color: black;">&#40;</span><span style="color: purple;">name</span><span style="color: black;">,</span> url<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span>
    <span style="color: purple;">name</span> <span style="color: black;">=</span> <span style="color: purple;">name</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: green; font-style: italic;">/[\[]/</span><span style="color: black;">,</span> <span style="color: red;">&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\[</span>&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: green; font-style: italic;">/[\]]/</span><span style="color: black;">,</span> <span style="color: red;">&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\]</span>&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
    <span style="color: purple;">var</span> regexS <span style="color: black;">=</span> <span style="color: red;">&quot;[<span style="color: #000099; font-weight: bold;">\\</span>?&amp;amp;]&quot;</span> <span style="color: black;">+</span> <span style="color: purple;">name</span> <span style="color: black;">+</span> <span style="color: red;">&quot;=([^&amp;amp;#]*)&quot;</span><span style="color: black;">;</span>
    <span style="color: purple;">var</span> regex <span style="color: black;">=</span> <span style="color: purple;">new</span> RegExp<span style="color: black;">&#40;</span>regexS<span style="color: black;">&#41;</span><span style="color: black;">;</span>
    <span style="color: purple;">if</span> <span style="color: black;">&#40;</span><span style="color: purple;">typeof</span> <span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span> <span style="color: black;">==</span> <span style="color: red;">'undefined'</span><span style="color: black;">&#41;</span> url <span style="color: black;">=</span> window.<span style="color: black;">location</span>.<span style="color: black;">href</span><span style="color: black;">;</span>
    <span style="color: purple;">var</span> results <span style="color: black;">=</span> regex.<span style="color: black;">exec</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span><span style="color: black;">;</span>
    <span style="color: purple;">if</span> <span style="color: black;">&#40;</span>results <span style="color: black;">==</span> <span style="color: purple;">null</span><span style="color: black;">&#41;</span>
        <span style="color: purple;">return</span> <span style="color: red;">&quot;&quot;</span><span style="color: black;">;</span>
    <span style="color: purple;">else</span>
        <span style="color: purple;">return</span> results<span style="color: black;">&#91;</span><span style="color: red;">1</span><span style="color: black;">&#93;</span><span style="color: black;">;</span>
<span style="color: black;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: WebDevVote.com</title>
		<link>http://prettycode.org/2009/04/21/javascript-query-string/comment-page-1/#comment-7</link>
		<dc:creator>WebDevVote.com</dc:creator>
		<pubDate>Wed, 22 Apr 2009 16:39:58 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=145#comment-7</guid>
		<description>You are voted!
Track back from http://webdevvote.com</description>
		<content:encoded><![CDATA[<p>You are voted!<br />
Track back from <a href="http://webdevvote.com" rel="nofollow">http://webdevvote.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Garry Shutler</title>
		<link>http://prettycode.org/2009/04/21/javascript-query-string/comment-page-1/#comment-6</link>
		<dc:creator>Garry Shutler</dc:creator>
		<pubDate>Wed, 22 Apr 2009 14:00:32 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=145#comment-6</guid>
		<description>Why no make toString just return window.location.search? Saves encoding what you just decoded.</description>
		<content:encoded><![CDATA[<p>Why no make toString just return window.location.search? Saves encoding what you just decoded.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
