Remove URL parameter with JavaScript

1

I'm creating a feature for a system and I came across the need to manipulate URL parameters, so I would like to know how to delete a certain parameter from the URL?

Here's a clearer example:

http://site.com.br?c=cliente&a=editar&id=31228

I need to remove the a=editar parameter from the URL, I tried to do this:

var urlReplace = document.URL.replace('&a=editar','');

or

var urlReplace = document.URL.replace(/&a=editar/g,'');

However, neither form worked!

    
asked by anonymous 22.01.2015 / 22:54

1 answer

2

If you do it works like this:

window.location = document.URL.replace('&a=editar','');

Remembering that the page will be reloaded.

    
22.01.2015 / 23:02