HTML onpageshow Attribute

HTML onpageshow Attribute: This attribute is defined as when a user navigates to a webpage then onpageshow events occurs. It occurs every time when the page is loaded whereas the onload event does not occur when the page is loaded from cache. The onpageshow attribute is the part of the Event Attributes.

HTML onpageshow Attribute

This attribute can be applied to the <body> element. This event contains a single attribute script. The script is to be run on onpageshow events. This event is used within the body tag.

Syntax: <element onpageshow = “script”> 



Browser Support:

This attribute is supported by the following browsers:

  • Chrome
  • Firefox
  • Safari-5.0
  • Opera
  • Internet Explorer-11.0

Example: for <body> element

<!DOCTYPE html>
<html>
<body onpageshow="myFunction()">
<h1>Hello World!</h1>
<script>
function myFunction() {
  alert("Welcome!");
}
</script>

</body>
</html>

Output:

Hello World!