Remove URL parameter using javascript


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,
Who is Participating?
aescntConnect With a Mentor Commented:
Ooops, actually it'd be =[\?&])q(?:=[^&]*)?/,'$1')

It may or may not be what you're looking for but try it.
HonorGodSoftware EngineerCommented:

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

  url = url.replace( /\bcapability_page\b/, '' );
the querystring is at "". replacing it with another value will reload the page.
The code would've been: =[\?&]capability_page(?:=[^&]*)?/,'')
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.