开发者

Stop reload when using window.location

On click of a开发者_如何学C 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?


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


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜