Skip to content Skip to sidebar Skip to footer

Warn the user if leave the current page using javascript

In some situations, users have a chance to wrongly press the back, close or reload button in the browser, if we want to show any warning message we can use the onbeforeunload event.

Example

    window.onbeforeunload = function() {

        return "Are you sure to go back?";

    };



Example Program:- (Editor)


The editor is Loading...

Advertisement

Post a Comment for "Warn the user if leave the current page using javascript"