Javascript Get URL contents
<p>I apologize up front if this question has been asked before. I tried searching for the answer but could not locate it. On my website, I have a click event that changes the url in the address bar without refreshing the page.</p>

<p>example:
<a href="http://www.plantcombos.com/html/hd_viewer.php?plant_Id=1256&amp;tag_Id=4874&amp;photo_Id=4570" rel="nofollow">http://www.plantcombos.com/html/hd_viewer.php?plant_Id=1256&amp;tag_Id=4874&amp;photo_Id=4570</a>
Changes to:
<a href="http://www.plantcombos.com/html/hd_viewer.php?plant_Id=738&amp;tag_Id=4386&amp;photo_Id=4120" rel="nofollow">http://www.plantcombos.com/html/hd_viewer.php?plant_Id=738&amp;tag_Id=4386&amp;photo_Id=4120</a></p>

<p>Now I am trying to extract the variable in the url by doing this:
    var photo = getUrlVars()['photo_Id'];</p>

<pre><code>function getUrlVars() {
var vars = {};
var parts = window.location.search.replace(/[?&amp;]+([^=&amp;]+)=([^&amp;]*)/gi, function(m,key,value) {
    vars[key] = value;
});
return vars;
</code></pre>

<p>}</p>

<p>This works to an extent. when I alert out the variable "photo" I get the photo Id of the original url. No matter how many times the url in the address bar changes, I will always get photo = 4570. Can anyone help explain how I might go about getting this variable to retrieve the correct value based on the new url that is displayed. Any help would be greatly appreciated. Thanks.</p>
