views:

73

answers:

4
+3  Q: 

javascript problem

Hi All, on click of a button I am changing window.location.href i.e. I am adding one query string parameter.This causes the page to be refreshed[as i am changing window.location.href]. I want to know is it possible to stop this page refresh and append the query string in the url?

+7  A: 

No. You can change the #hashstring, but changing the query string results in a reload.

Kobi
thanks for ur help.
Wondering
+5  A: 

Any assignment of new values to the location object from JavaScript will load a new page.

It is possible to change the hash value without refreshing the page but not the query string.

See this thread: http://www.sitepoint.com/forums/showthread.php?t=552076

Ravia
+3  A: 

Take a look at this thread, maybe it will help you.

Reigel
+2  A: 

If you append a #hashstring the page will not reload. In addition, if the user hits the back button on the browser it will remove the #hashstring. The #hashstring can be useful for saving state in the URL bar without causing a reload and can be coupled with ajax calls.

It's important to note that the #hashstring will not be sent to the server and is only visible to the web browser. For example: http://example.com/#blah

Will generate a http request that looks like:

GET / HTTP/1.1
Host: example.com

The #blah does not get sent down to the server by the browser.

Joseph Kim
I didn't know browsers don't send the hash to servers. Interesting. +1, and welcome to Stack Overflow.
Kobi