Solved

Remove URL parameter using javascript

Posted on 2006-11-21
3
1,844 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

740 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