Hello everyone please let know how to show a popup on hover when user close a browser . It's possible or not
Loading
Hello everyone please let know how to show a popup on hover when user close a browser . It's possible or not
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Jan 16, 2023, 2:15 AM EST
There is no specific event for capturing the browser close event.
You can only capture on unload of the current page.
$(window).unload(function() { //do something });By this method, it will be effected while refreshing / navigating the current page.
Even calculating of X Y position of the mouse event doesn't give you good result.
Jignesh KumarRank #91 · 22.9K reputationPosted Jan 16, 2023, 4:01 AM EST
Hello Anukesh,
You can use "beforeunload" to show pop up,
https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
Deepak RawatRank #646 · 3.7K reputationPosted May 12, 2023, 6:56 AM EDT
window.addEventListener('beforeunload', function(event) { // Cancel the default event (optional) event.preventDefault(); // Customize the message to display in the popup var message = 'Are you sure you want to leave this page?'; // Display the popup event.returnValue = message; return message; });Tuhin PaulRank #7 · 71.9K reputationPosted May 12, 2023, 11:14 PM EDT
Unfortunately, it is not possible to show a popup on hover when the user closes a browser tab or window using the onbeforeunload or unload events, because for the two methods you need to return a string. Infact you cannot use your own dialog boxes (or jQueryUI modal dialogs) to override beforeunload method.
One option would be to use a service like Notify.js, which allows you to show notifications even when the user is about to close the browser.
Another option would be to use a browser extension like Stay.js, which prevents the user from closing the browser tab or window until they have dismissed the notification.
Check out this link:
https://stackoverflow.com/questions/52758117/how-to-display-popup-with-custom-html-on-browser-close-tab-using-javascript-jque