utcghghvgh
utcghghvgh

Reputation: 119

Set location.pathname and location.search together?

I want to do something like

 location.pathname = "/abc"
 location.search = "name=test"

It ends up getting redirected to /abc. I want the redirection to happen to /abc?name=test

Upvotes: 5

Views: 2718

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074028

Just set the location (or location.href):

location = "/abc?name=test";

Since it's a relative URL, the protocol and host will be unchanged.

Upvotes: 4

Related Questions