1 /* Copyright (c) 2006-2007 Mathias Bank (http://www.mathias-bank.de)
2 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
3 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
8 * Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
9 * Tom Leonard for some improvements
14 * Returns get parameters.
16 * If the desired param does not exist, null will be returned
18 * To get the document params:
19 * @example value = $(document).getUrlParam("paramName");
21 * To get the params of a html-attribut (uses src attribute)
22 * @example value = $('#imgLink').getUrlParam("paramName");
24 getUrlParam: function(strParamName){
25 strParamName = escape(unescape(strParamName));
27 var returnVal = new Array();
30 if ($(this).attr("nodeName")=="#document") {
33 if (window.location.search.search(strParamName) > -1 ){
35 qString = window.location.search.substr(1,window.location.search.length).split("&");
38 } else if ($(this).attr("src")!="undefined") {
40 var strHref = $(this).attr("src")
41 if ( strHref.indexOf("?") > -1 ){
42 var strQueryString = strHref.substr(strHref.indexOf("?")+1);
43 qString = strQueryString.split("&");
45 } else if ($(this).attr("href")!="undefined") {
47 var strHref = $(this).attr("href")
48 if ( strHref.indexOf("?") > -1 ){
49 var strQueryString = strHref.substr(strHref.indexOf("?")+1);
50 qString = strQueryString.split("&");
57 if (qString==null) return null;
60 for (var i=0;i<qString.length; i++){
61 if (escape(unescape(qString[i].split("=")[0])) == strParamName){
62 returnVal.push(qString[i].split("=")[1]);
68 if (returnVal.length==0) return null;
69 else if (returnVal.length==1) return returnVal[0];
70 else return returnVal;