Mostafa Talebi
Mostafa Talebi

Reputation: 9173

Editing window.location.hash will cause the query string to be removed

I have the following string:

http://example.com/?phrase=samplePhrase

And when I click on a certain element the URL receives a hash-edit like this:

#show/item

Using this javascript code:

window.location.hash =  "/" + "show" + "/" + "item";

But I want just this hash-edit to append to whatever current URL is. So to have:

http://example.com/?phrase=samplePhrase#show/item

But it first remove what ever query string is and then makes url like this:

http://example.com/#/show/item

Can anyone help please?

Upvotes: 2

Views: 1335

Answers (1)

Evicted Cache
Evicted Cache

Reputation: 1401

If you need to get the params out of the URL, you should be able to do something like this:

var params = window.location.search;
window.location.hash =  params + "#" + "show" + "/" + "item";

Upvotes: 1

Related Questions