Last active
August 29, 2015 13:56
-
-
Save normanzb/9211247 to your computer and use it in GitHub Desktop.
Quick url parameter appending
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function appendParam(url, param){ | |
| var parts = url.split(/\?([^#]*)#?/); | |
| var host = parts.shift(); | |
| var hash = parts.pop(); | |
| var params = parts == 0 ? [] : parts.join('?').split('&'); | |
| params.push(param); | |
| return host + '?' + params.join('&') + ((hash == null || hash == 0) ? '' : ('#' + hash)); | |
| }; |
Author
function appendParam(url, param){
var parts = url.split(/?([^#]*)#?/);
var host = parts.shift();
var hash = parts.pop();
var params = parts == 0? [] : parts.join('?').split('&');
params.push(param);
return host + '?' + params.join('&') + ((hash == null || hash == 0) ? '' : ('#' + hash));
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://example.com:80/docs/books/tutorial/index.html?name=networking#DOWNLOADING