Javascript DOM onpageshow Event find it page was cached

Introduction

Find out whether the page was cached by the browser:

View in separate window

<!DOCTYPE html>
<html>
<body onpageshow="myFunction(event)">
<p id="demo"></p>
<script>
function myFunction(event) {/*from w ww  .  j a va  2  s. c o m*/
  if (event.persisted) {
    document.getElementById("demo").innerHTML = "The page was cached by the browser";
  } else {
    document.getElementById("demo").innerHTML = "The page was NOT cached by the browser";
  }
}
</script>

</body>
</html>



PreviousNext

Related