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");
});
How do you pop up an alert box when the browsers refresh button is clicked? You can do it like this: window. onbeforeunload = function() { return “Data will be lost if you leave the page, are you sure?”; };
One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.
JavaScript Popup Boxes: Summary If you want to display an alert of some kind to a user, use alert() . If you want to display a confirmation box with option buttons, use confirm() . If you want to use a pop up with an input and option buttons, which can display inputed values, use prompt() .
Hui, a old post. But i´m looking too for a solution to add a script after reload when click a order save button in woocommerce admin order. I think it is a great way to use the sessionStorage and not some hooks. Thanks to Akhil for open the eyes. Maybe some one looking too:
jQuery('.button.save_order.button-primary').click(function() {
sessionStorage.setItem('save_order',true);
});
jQuery( function () {
if ( sessionStorage.getItem('save_order') ) {
alert( "Hello world" );
sessionStorage.removeItem('save_order');
}
});
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With