[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1868
  • Last Modified:

Remove URL parameter using javascript

Hello,

I have an onclick js function.  The function works well with passing the querystring parameters in the URL, but I need to add a few more lines to do the following:

If "capability_page" URL parameter exists in URL, remove it.

I imagine that it is rather simple to determine if a parameter exists within the URL?  Don't know how difficult it is to remove a URL parameter.

Any js gurus out there that can help?

Thank you,
Jayme
0
jayme9
Asked:
jayme9
  • 2
1 Solution
 
HonorGodCommented:

  if variable "url" contains the string, then you can:

  url = url.replace( /\bcapability_page\b/, '' );
0
 
aescntCommented:
the querystring is at "location.search". replacing it with another value will reload the page.
The code would've been: location.search = location.search.replace(/[\?&]capability_page(?:=[^&]*)?/,'')
0
 
aescntCommented:
Ooops, actually it'd be
   location.search = location.search.replace(/([\?&])q(?:=[^&]*)?/,'$1')

It may or may not be what you're looking for but try it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now