Moreover, If you click on a link or click on something which gonna navigate away from the webpage it will also prompt you.
Below I am providing a full example so that you can understand it properly.
Remeber earlier versions of browsers allowed you to set custom messages in the alert dialog box, But now it’s not possible. The custom alert message can’t be set now. See the special notes added in the bottom of this tutorial post.
Just include your jQuery. (you can use CDN like Google, <script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> )
Or you can simply download jquery.min.js and include that.
Now just test it on your browser.
If you click on google link it will prompt you.
Below is the screenshot of the alert message
If you try to close the current tab the same message will appear.
Special Notes: confirm() method can take messages in the form of string as a parameter, but the newer versions of chrome and other browsers do not allow you to use custom messages in the alert box.