How to show an alert after reloading the page in JavaScript?
You can use sessionStorage
:
$( "button" ).click( function () {
sessionStorage.reloadAfterPageLoad = true;
window.location.reload();
}
);
$( function () {
if ( sessionStorage.reloadAfterPageLoad ) {
alert( "Hello world" );
sessionStorage.reloadAfterPageLoad = false;
}
}
);
That's called onload. It came waaaaay before DOM ready was around, and DOM ready was actually created for the exact reason that onload waited on images.
window.onload = function () {
alert("It's loaded!");
//dom not only ready, but everything is loaded
}
And a jQuery Javascript solution is to bind the window.onload event in document.ready().
$(window).bind("load", function() {
// code here
});