Fengzhimei@Dot.Net
Designing My Colorful Dream

Used to add your querystring to an URL, it can judge if the querystring you try to add is exist in the URL, if so, replace it with new value, or expand the URL.

function ExpandQS(queryStringName, queryStringValue)
{
    
var returnValue;
    
var currHref = window.location.href.substring(0,(window.location.href.length-window.location.search.length));
    
var currQuery = window.location.search.substring(1);
    
var args = currQuery.split('&');
    
var keyValuePairs = new Object();
    
if(currQuery) {
        
for(var i=0; i < args.length; i++{
            
var value;
            
var pair = args[i].split('=');
            
var name = unescape(pair[0]);

            
if (pair.length == 2){
                value 
= unescape(pair[1]);
            }

            
else{
                value 
= name;
            }
      
            keyValuePairs[name] 
= value;
        }

        
        keyValuePairs[queryStringName] 
= queryStringValue;
        
        
var newQuery = "";
        
        
for(var key in keyValuePairs){
            newQuery 
+= key + "=" + keyValuePairs[key] + "&";
        }

        
        newQuery 
= newQuery.substring(0, newQuery.length - 1);
        
        returnValue 
= currHref + "?" + newQuery;
    }

    
else{
        returnValue 
= currHref + "?" + queryStringName + "=" + queryStringValue;
    }

    
return returnValue;
}

Hopefully, it's useful to you.
posted on 2006-06-12 10:02  fengzhimei  阅读(838)  评论(0编辑  收藏  举报