Skip to content

Get-Parameter mit jQuery auslesen

von dennis

Ein kleines Plugin, gefunden hier: http://jquery-howto.blogspot.de/2009/09/get-url-parameters-values-with-jquery.html

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

Und so funktionierts:

// Objekt mit allen Parametern:
var allVars = $.getUrlVars();
 
// Ein einzelner Parameter:
var byName = $.getUrlVar('name');

Aus → JavaScript

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS