Is it possible to update the address bar without accessing the server?

I have a treeview implemented in CSS, when a user clicks on a folder in a tree, I would like to update the URL in the address bar without causing a server callback.

HTML looks something like this: -

<ol> <li> <a href="www.example.com/blah?id=12345">Folder</a> <ol> <li>Child</li> </ol </li> <ol> 

In the CSS that I am processing, the folder expands, but I would like the URL of the address bar to be updated, so I can deeply bind to a specific folder, but there is no need from the code point of view to make a round-trip server Is there a way to achieve of this? I have a feeling that this may not be possible due to a fictitious infection ???

I use HTML5, CSS2 / 3, jquery and ASP.NET MVC3

+4
source share
2 answers

Yes, with the HTML 5 history API you can, as is done on gawker sites and on github . But the condition is that both pages belong to the same server. How can you change the address:

 http://www.exemple.com/page1.html 

in

 http://www.exemple.com/page2.html 

using the history.replaceState function. It is not widely supported in all browsers ( caniuse ). Best to use history.js

+4
source

HTML5 adds a history API that allows history.pushState() to be used in modern browsers to update the URL. For security reasons, you are limited to the same domain.

This will not be supported in IE until IE10. Firefox, Safari, Opera and Chrome have all implemented this.

+5
source

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


All Articles