Element.fromQueryString(), Window.fromQueryString(), String.fromQueryString()
Snippets are small pieces of code that do not fit in the UvumiTools plugin category. Please note that each of these semi-useful functions requires Mootools 1.2.
Does the opposite of Mootools' toQueryString() function: generates a Hash from an URL with a query string. The Hash will contain an entry for each parameter of the query string. The function can be applied to:
- An element: if this element is an <a> or a <form>, the function will try to extract any parameter contained in the href or the action property.
- Window or Document: Will try to extract the query string from the current page location.
- A string: You might get a URL from some other source (not an element or the document), so this function also works directly on strings.
If the element/window/string does not contain any parameters, the function will return false.
case 'document':
break;
break;
break;
break;
break;
var parameters = false;
if(url.contains('?')){
var query = url.split('?')[1];
if(query != ""){
params = query.split('&');
params.each(function(param){
parameters.set(param[0],param[1]);
return parameters;
Usage:
window.fromQueryString(); //returns a Hash containing the parameters of the current page
"snippets.html".fromQueryString(); //returns False
var params = "snippets.html?fruit=apple&animal=cat".fromQueryString(); //store the paramters in 'params'
alert(params.get('animal')); //alerts 'cat'
Demo: http://uvumitools.com/snippets.html?snippet=querystring&fruit=apple&animal=cat#foo
In this demo, we simply stop the click event on that link, call the function on it, and alert the resulting Hash. Just click the link and you'll see. Notice how the 'foo' after the '#' is dropped.