Primitive QueryString Param Extractor Plugin


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

Extracts a string paremeter from the url query string. Basic operation wont handle multiples such as radio buttons etc. Just gets the first instance of the name and returns it's value.


Copy this code and paste it in your HTML
  1. (function($) {
  2. /* --------------------------------------------------------------------- */
  3. /*
  4.   * Extracts a string parameter from the url query string. Basic operation
  5.   * wont handle multiples such as radio buttons etc. Just gets the first
  6.   * instance of the name and returns it's value.
  7.   *
  8.   * @param {String} Name of value to extract from URL QueryString.
  9.   * @returns {String} Value of QueryString attribute or null if not found
  10.   */
  11. $.param = function(name) {
  12. var exp = new RegExp('[\\?&]' + name + '=([^&#]*)');
  13. var param = exp.exec(window.location.href);
  14. return (param) ? param[1] : null;
  15. }
  16.  
  17. })(jQuery);
  18.  
  19.  
  20. /* EXAMPLE USAGE */
  21. /* Looks for a PageConfig object first then the Section querystring param */
  22.  
  23. $(function() {
  24. $('#tabs li a>span:contains(' +
  25. (($.PageConfig || {}).section || $.param("Section")) || "Home" +
  26. ')').parent().addClass("current");
  27. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.