javascript alert not refresh page code example
Example 1: alert without page refresh
// note that its the return false; that prevents the page refresh.
<button onclick="alert('Hello'); return false;">Click</button>
Example 2: javascript alert on refresh
window.onbeforeunload = function() {
return "Data will be lost if you leave the page, are you sure?";
};