user892134
user892134

Reputation: 3224

Remove parameter from url not working

I'm attempting to remove a url parameter status from the url but in the following alert, the parameter is still there.

var addressurl = location.href.replace(separator + "status=([^&]$|[^&]*)/i", "");
        alert(addressurl);
            location.href= addressurl;

How do i solve?

Upvotes: 0

Views: 44

Answers (3)

rajuGT
rajuGT

Reputation: 6404

Javascript context in web pages are to the page you are working on.

When you reload, redirect or move to any other page, javascript changes done in previous page will not be there. This has to be handled from server side.

Upvotes: 1

hjpotter92
hjpotter92

Reputation: 80629

You are confusing regex with strings.

It should be:

var addressurl = location.href.replace(separator, '').replace(/status=([^&]$|[^&]*)/i", "");

Upvotes: 2

Russell Steen
Russell Steen

Reputation: 6612

Refresh repeats the last request to the server, which is going to ignore your javascript changes. Instead navigate to the new url with window.location = addressurl;

Upvotes: 0

Related Questions