Remove query string from URL in JavaScript?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Remove query string from URL in JavaScript?

Post 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'
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Remove query string from URL in JavaScript?

Post by Chris Corbyn »

[js]var url = new String(window.location);alert(url.replace(/\?.*$/, ""));[/js]
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Remove query string from URL in JavaScript?

Post by JAB Creations »

Thank you very much Chris, that worked great!
Post Reply