Get URL Parameters with jQuery | Improved


/ Published in: jQuery
Save to your folder(s)

This is an improvement on http://snipplr.com/view/11583/retrieve-url-params-with-jquery/
I found IE wasn't liking the results[1] when no param was set. This fixes that issue.


Copy this code and paste it in your HTML
  1. $.urlParam = function(name){
  2. var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
  3. if (!results) { return 0; }
  4. return results[1] || 0;
  5. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.