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
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
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.
You can use this simple regex:
yourUrl.replace(/\?.+/, '')
reomve()
is for DOM stuff.
Try this snippet:
var url = "http://www.somexample.com?a=b&c=2&d=3";
url = url.substring(0 , url.indexOf('?')+1);
Posting this that worked for me in Python 3 as some of the other solutions didn't.
import re
mystring = 'http://www.example.com?some_parameters_continue_forever'
mystring_clean = re.sub(r'\?.*', '', mystring)
print(mystring_clean)