mdn-ajax-nav-example
mdn-ajax-nav-example copied to clipboard
oEvent.state is null
Discovered in Chrome 64.0.3282.119
Steps to reproduce:
- Navigate to: first_page.php
- Click "Second Page" link.
- Use browser's Back button to go back to first_page.php
Unexpected Results:
- Content is still "This is the content of second_page.php."
- Title is "Second Page"
- Javascript console throws error:
Uncaught TypeError: Cannot read property 'title' of null at onpopstate (ajax_nav.js:192)
Issue appears to be due to PopStateEvent object's state
property being null. Did a quick bit of research, and found the following SO post on why this occurs:
https://stackoverflow.com/questions/11092736/window-onpopstate-event-state-null
Apparently, the first page loaded (the one loaded directly through browser, not through ajax request) doesn't have a "state" since it wasn't entered into the history stack via pushState
.