Skip to content

JavaScript onpageshow Event

Why onpageshow ?

The JavaScript onpageshow property occurs when the page is loaded. But not immediately. onload occurs immediately after the page is loaded. onpageshow takes place after the onload feature (another difference is the time to load in the cache).

<element onpageshow=”script”>

  • script: Codes to load when loading a web page.

JavaScript onpageshow Examples

Example 1

onpageshow example 1
<body onpageshow="onPageShowFunction()">

  <p>onpageshow experiment</p>

        function onPageShowFunction() {
            alert("onpageshow worked successfully")


Example 2

onpageshow example 2
  window.addEventListener("pageshow", onPageShow);

        function onPageShow() {
            alert("onpageshow worked successfully")

Example 3

onpageshow example 3
<body onload="onloadFunction()" onpageshow="onpageFunction()">

    <h2>onload VS onpageshow</h2>


        function onloadFunction() {

        function onpageFunction() {


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: