Solved

Remove URL parameter using javascript

Posted on 2006-11-21
3
1,847 Views
Last Modified: 2012-05-05
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
Comment
Question by:jayme9
[X]
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
3 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 17989401

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

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

Expert Comment

by:aescnt
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(?:=[^&]*)?/,'')
0
 
LVL 6

Accepted Solution

by:
aescnt earned 50 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.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

724 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