Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Remove URL parameter using javascript

Posted on 2006-11-21
Medium Priority
Last Modified: 2012-05-05

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,
Question by:jayme9
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 41

Expert Comment

ID: 17989401

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

  url = url.replace( /\bcapability_page\b/, '' );

Expert Comment

ID: 17992358
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(?:=[^&]*)?/,'')

Accepted Solution

aescnt earned 200 total points
ID: 17992378
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.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question