mdn-ajax-nav-example icon indicating copy to clipboard operation
mdn-ajax-nav-example copied to clipboard

oEvent.state is null

Open crazytonyi opened this issue 7 years ago • 0 comments

Discovered in Chrome 64.0.3282.119

Steps to reproduce:

  1. Navigate to: first_page.php
  2. Click "Second Page" link.
  3. Use browser's Back button to go back to first_page.php

Unexpected Results:

  1. Content is still "This is the content of second_page.php."
  2. Title is "Second Page"
  3. 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 .

crazytonyi avatar Feb 01 '18 23:02 crazytonyi