Skip to content

Instantly share code, notes, and snippets.

@cferdinandi
Created August 6, 2019 13:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cferdinandi/bceb240cf974dd8c2170ea6f007dce76 to your computer and use it in GitHub Desktop.
Save cferdinandi/bceb240cf974dd8c2170ea6f007dce76 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>1 | Safari Bug</title>
<style type="text/css">
body {
margin: 0 auto;
max-width: 40em;
width: 88%;
}
</style>
<script>
/**
* If browser back button was used, flush cache
* This ensures that user will always see an accurate, up-to-date view based on their state
* https://stackoverflow.com/questions/8788802/prevent-safari-loading-from-cache-when-back-button-is-clicked
*/
(function () {
window.onpageshow = function(event) {
if (event.persisted) {
window.location.reload();
}
};
})();
</script>
</head>
<body>
<p id="app"></p>
<p><a href="2.html">Next Page &rarr;</a></p>
<script>
var app = document.querySelector('#app');
app.textContent = new Date().toLocaleTimeString();
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>2 | Safari Bug</title>
<style type="text/css">
body {
margin: 0 auto;
max-width: 40em;
width: 88%;
}
</style>
<script>
/**
* If browser back button was used, flush cache
* This ensures that user will always see an accurate, up-to-date view based on their state
* https://stackoverflow.com/questions/8788802/prevent-safari-loading-from-cache-when-back-button-is-clicked
*/
(function () {
window.onpageshow = function(event) {
if (event.persisted) {
window.location.reload();
}
};
})();
</script>
</head>
<body>
<p id="app"></p>
<script>
var app = document.querySelector('#app');
app.textContent = new Date().toLocaleTimeString();
</script>
</body>
</html>
@huntlyc
Copy link

huntlyc commented Jul 2, 2020

Had a JS powered form that was misbehaving on back (some fields set, some waiting on user input) - using this allowed me to wipe the slate clean, thank you! 👍 🥇

@cferdinandi
Copy link
Author

👍

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