Page 1 of 1

Remove query string from URL in JavaScript?

Posted: Sat Apr 26, 2008 7:17 pm
by JAB Creations
I'm trying to remove any existing queries from the window.location in JavaScript. I'm trying to add my own query though it must be the only query when the next page is loaded...

Code: Select all

var go_to = self.location = self.location.protocol+'//'+self.location.host+self.location.pathname-self.location.search;window.location = go_to + '?only_my=query'

Re: Remove query string from URL in JavaScript?

Posted: Sun Apr 27, 2008 1:55 am
by Chris Corbyn
[js]var url = new String(window.location);alert(url.replace(/\?.*$/, ""));[/js]

Re: Remove query string from URL in JavaScript?

Posted: Sun Apr 27, 2008 3:27 am
by JAB Creations
Thank you very much Chris, that worked great!