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

asked Jun 26, 2012 at 13:56
3
  • regular expressions are your friends :) Commented Jun 26, 2012 at 13:57
  • 1
    possible duplicate of add or update query string parameter Commented Jun 26, 2012 at 13:58
  • "http://example.com/main/index.php?code=hads1328fas&store=food#home".replace(/code=[^&]*/, '') Should do Commented Jun 26, 2012 at 14:00

1 Answer 1

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
answered Jun 26, 2012 at 14:01
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.