"Create an urlAppend function that appends strings to urls and handles ? and & appropriately". r=crschmidt (closes #2297)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9730 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2009-10-08 16:48:50 +00:00
parent 3e0b053009
commit ab2b2356f1
3 changed files with 68 additions and 19 deletions

View File

@@ -628,6 +628,30 @@ OpenLayers.Util.getParameterString = function(params) {
return paramsArray.join("&");
};
/**
* Function: urlAppend
* Appends a parameter string to a url. This function includes the logic for
* using the appropriate character (none, & or ?) to append to the url before
* appending the param string.
*
* Parameters:
* url - {String} The url to append to
* paramStr - {String} The param string to append
*
* Returns:
* {String} The new url
*/
OpenLayers.Util.urlAppend = function(url, paramStr) {
var newUrl = url;
if(paramStr) {
var parts = (url + " ").split(/[?&]/);
newUrl += (parts.pop() === " " ?
paramStr :
parts.length ? "&" + paramStr : "?" + paramStr);
}
return newUrl;
};
/**
* Property: ImgPath
* {String} Default is ''.