Stop reloading when using window.location

When I click the button, it changes window.location.href , that is, I add one query string parameter. This causes the page to refresh (as I change window.location.href ). I want to know if it is possible to stop updating this page and add a query string to the URL?

+4
source share
4 answers

Not. You can change #hashstring , but changing the query string will result in a reboot.

+8
source

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

You can change the hash value without refreshing the page, but not the query string.

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

+6
source

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

+3
source

If you add #hashstring, the page will not reload. In addition, if the user clicks the back button in the browser, he removes #hashstring. #hashstring can be useful for storing state in a URL string without causing a reboot and can be connected to ajax calls.

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

Will generate an HTTP request that looks like this:

 GET / HTTP/1.1 Host: example.com 

#blah is not sent to the server by the browser.

+3
source

Source: https://habr.com/ru/post/1299298/


All Articles