最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Stop reload when using window.location - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Mar 31, 2013 at 21:18 Andrew Whitaker 126k32 gold badges295 silver badges308 bronze badges asked Jan 25, 2010 at 8:58 WonderingWondering 5,07622 gold badges72 silver badges90 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 8

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)

  1. 暂无评论