Q:

How to show an alert after reloading the page in JavaScript?

I am trying to make alert box after page reloaded, but it doesn't work.
Please correct my code and tell me why?
$("button").click(function(){
    window.location.reload();
    alert("Hello world");
});

A:

You can use sessionStorage:
$( "button" ).click( function () {
        sessionStorage.reloadAfterPageLoad = true;
        window.location.reload();
    } 
);

$( function () {
        if ( sessionStorage.reloadAfterPageLoad ) {
            alert( "Hello world" );
            sessionStorage.reloadAfterPageLoad = false;
        }
    } 
);

