I was wondering if I can remove everything after a question mark in a URL?
http://www.site.com?some_parameters_continue_forever
can I just use .remove()
? What would need to be put inside the parameters?
Thanks
To remove a querystring from a url, use the split() method to split the string on a question mark and access the array element at index 0 , e.g. url. split('? ')[0] . The split method will return an array containing 2 substrings, where the first element is the url before the querystring.
Just pass in the param you want to remove from the URL and the original URL value, and the function will strip it out for you. To use it, simply do something like this: var originalURL = "http://yourewebsite.com?id=10&color_id=1"; var alteredURL = removeParam("color_id", originalURL);
Its name is query string. After the question mark you can pass key-value pairs and use them server-side.
Since the url is controlled by the browser when you change the url the page will reload. Still for what you want to do, on pages where you don't need the stuff after the ?
mark type..
window.location = "http://www.mysite.com" //or whatever your site url is
To dynamically do this you can use the below function and then use window.location
function getPathFromUrl(url) {
return url.split("?")[0];
}
Note: When you change the url the page will refresh.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With