Javascript DOM onpageshow Event

Introduction

Execute a JavaScript when a user navigates to a webpage:

View in separate window

<!DOCTYPE html>
<html>
<body onpageshow="myFunction()">
<p id="demo"></p>
<script>
function myFunction() {//from w w  w .j a v a  2 s .  c om
  document.getElementById("demo").innerHTML = "Welcome!";
}
</script>

</body>
</html>

The onpageshow event occurs when a user navigates to a webpage.

To find out if a page is loaded directly from the server or if the page is cached, use the persisted property of the PageTransitionEvent object.

This property returns true if the page is cached by the browser, and false otherwise.

Bubbles: No
Cancelable: No
Event type: PageTransitionEvent
Supported HTML tags: <body>



PreviousNext

Related