Skip to content

Instantly share code, notes, and snippets.

@lrowe
Last active December 17, 2015 04:29
Show Gist options
  • Save lrowe/5551102 to your computer and use it in GitHub Desktop.
Save lrowe/5551102 to your computer and use it in GitHub Desktop.
Problem with pushState and back button in Safari/Chrome.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store" />
<script>
function navigate() {
var missing_url = window.location.pathname + '/missing'
window.history.pushState({test:'test'}, 'new page', missing_url);
// Reloading will return the 404
window.location.reload();
}
</script>
</head>
<body>
<p>Click the button to navigate to a missing page with pushSate and reload.</p>
<button onclick="navigate()">Navigate</button>
<p>Subsequently clicking back does not reload this page on Chrome or Safari but leaves you on the 'missing' 404 page. With Firefox you are returned to this page.</p>
</body>
</html>
@lrowe
Copy link
Author

lrowe commented May 9, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment