1

I want to remove the string code=hads1328fas& on my URL, so that

BEFORE

http://example.com/main/index.php?code=hads1328fas&store=food#home

AFTER

http://example.com/main/index.php?store=food#home

However, the string code=hads1328fas& may not always the same, so the code below won't works in this case.

var url = window.location.href;
url.replace('code=hads1328fas&')

Is there any way that is possible for the case?

Thanks

Charles Yeung
  • 38,347
  • 30
  • 90
  • 130

1 Answers1

3

Use regular expressions:

url = "http://example.com/main/index.php?code=hads1328fas&store=food#home";
url = url.replace(/code=[^&]+&/,'');

After this, url will contain

http://example.com/main/index.php?store=food#home
kba
  • 19,333
  • 5
  • 62
  • 89