$_GET() function to get any url parameter in javascript


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



Copy this code and paste it in your HTML
  1. function $_GET(a) {
  2. return (a = location.search.match(RegExp("[?&]" + a + "=([^&]*)(&?)", "i"))) ? a[1] : a
  3. }
  4.  
  5. // example, if browser's url was like:
  6. // http://www.google.co.in/search?q=web&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
  7. // then you can get the value of any parameter like: alert($_GET('rls'));
  8. // returns org.mozilla:en-US:official as an alert

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.