Bookmarking
Let's move back from the self-service restaurant to our marketing person who wants to know which URL they can use to put in a document as a link
to a page so that people can quickly access information that is found on the site. Perhaps they also want to know what to do if a visitor uses the bookmark
feature of the browser to save the URL of a (in our case, virtual) page to revisit later. We can support this thanks to the URL parts we used in our pushState
code.
In our examples, we made sure that we stored enough information about our updated page in the state that we pushed on the history stack, and you learned how to restore our page to its previous state using that information. In our pushState
code, we appended a query string to the URL that basically contains the same information. We can retrieve that information using the location
object of the browser and its href
property. Here is the code that will, if the URL with query string is used, cause our single page website...