I have a popup modal on my website similar to facebook's photo viewer. When the modal is opened, it is displaying content from another page and I want to change the address bar value and history to show this.
There is a dropdown in the modal that changes the content in the modal to that of a different page. When this happens, I once again want to change the address bar value and history to show the page was changed.
Essentially, I want to exactly replicate the behavior of facebook's photo viewer, which you can try out by:
Photos
I tried to create a JSFiddle to show where I am at with this, but JSFiddle apparently does not allow the history to be manipulated. As such, I've put my code online here, and which you can download from here.
A few key points:
You have to use history API, and specifically you have to use history.pushState()
history API
So when a user opens the modal you can do something :
history.pushState(stateObj, "page 2", "image\id.html");
Where : stateObj is the object that you pass through history, page 2 is the title and the last parameter is the URL you want to modify.
After you've done so you have to use on popstate event as the browser Back and Forward buttons won't reload the page.