mootools: GET-Parameter aus aktiver URL auslesen

mit der $get()-Erweiterung für Mootools

	var get = $get();  


	Function: $get
		This function provides access to the "get" variable scope + the element anchor
Version: 1.3
Arguments: key - string; optional; the parameter key to search for in the url's query string (can also be "#" for the element anchor) url - url; optional; the url to check for "key" in, location.href is default
Example: >$get("foo",""); //returns "bar" >$get("foo"); //returns the value of the "foo" variable if it's present in the current url(location.href) >$get("#",""); //returns "moo" >$get("#"); //returns the element anchor if any, but from the current url (location.href) >$get(,""); //returns {foo:'bar',bar:'foo'} >$get(,""); //returns {foo:'bar',bar:'foo',hash:'moo'} >$get(); //returns same as above, but from the current url (location.href) >$get("?"); //returns the query string (without ? and element anchor) from the current url (location.href)
Returns: Returns the value of the variable form the provided key, or an object with the current GET variables plus the element anchor (if any) Returns "" if the variable is not present in the given query string
Credits: Regex from [url=] Function by Jens Anders Bakke, */ function $get(key,url){ if(arguments.length < 2) url =../../../location.html if(arguments.length > 0 && key != ""){ if(key == "#"){ var regex = new RegExp("#(^$*)"); } else if(key == "?"){ var regex = new RegExp("?(^#$*)"); } else { var regex = new RegExp("?&"+key+"=(^&#*)"); } var results = regex.exec(url); return (results == null )? "" : results1; } else { url = url.split("?"); var results = {}; if(url.length > 1){ url = url1.split("#"); if(url.length > 1) results"hash" = url1; url0.split("&").each(function(item,index){ item = item.split("="); resultshref="0" class="knowledgebase-link">0 = item1; }); } return results; } }

Wiki-Datei des Artikels herunterladen