An easy way to get this is:
function getPathFromUrl(url) {
return url.split("?")[0];
}
For those who also wish to remove the hash (not part of the original question) when no querystring exists, that requires a little bit more:
function stripQueryStringAndHashFromPath(url) {
return url.split("?")[0].split("#")[0];
}
EDIT
@caub (originally @crl) suggested a simpler combo that works for both query string and hash (though it uses RegExp, in case anyone has a problem with that):
function getPathFromUrl(url) {
return url.split(/[?#]/)[0];
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…