Solved

Remove URL parameter using javascript

Posted on 2006-11-21
3
1,836 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
  • 2
3 Comments
 
LVL 41

Expert Comment

by:HonorGod
Comment Utility

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

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

Expert Comment

by:aescnt
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now