17876

How to show custom pop up when detect browser close event?

Question:

I am trying to find window/tab close event in Google Chrome. In goole chrome, unload() is not working. So i used

<body onbeforeunload="return OnBeforeUnLoad ()">

javascript Code :

function OnBeforeUnLoad() { return "Your tutorial will be finished unexpectedly"; }

It is working fine in Chrome. But it throws default pop up of chrome. I want my own pop up box.

So how can i do this ?

Answer1:

You cannot. Imagine an advertiser adding code to display a popup advert when the window is closed, or a trickster adding a popup which has "OK" and "Cancel" reversed or non-functional; it's back to the old days of the internet when browsers were too trusting and users were left occasionally needing to force-quit the browser just to escape a page.

To prevent it, these days sites are allowed to display a block of text within a standard popup. You have no more control than that.

The best proof I can offer is this: go to an online email provider and close the window while uploading something, or jsfiddle and close the window after editing something, or any major site where you can edit things without an autosave. Notice that they use the browser-standard popup. If there were an alternative, one of them would have used it.

Recommend

  • PHP, MySQL - load around 100k records and export them to xml
  • Can I place inside [closed]
  • windows could not start the service on local computer error 1067 on windows server 2008 SP1
  • Using Sphinx4.0 to build a speech recog. Android application
  • Incomplete data: Delta source ended unexpectedly while git svn fetch
  • Debian Jessie - Apache2 / PHP 5.6, can't upload more than 128kb
  • application closes after closing interstitial ad
  • Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2
  • Can someone please explain how this implementation of bucket sort works?
  • What is wrong with this emulation of CMPXCHG16B instruction?
  • Where to put clearQueue in jQuery code
  • In a MEAN stack, how can I do one-time MongoDB indexing?
  • Python PIL remove sections of an image based on its colour
  • Consuming a web service with the Netbeans Platform
  • Wait for .each() .getJSON request to finish before executing a callback
  • How do I translate LR(1) Parse into a Abstract syntax tree?
  • Authentication failed with Azure Active Directory in Windows Phone
  • Do query loads all the data in memory
  • Creating Java object from class name with constructor, which contains parameters [duplicate]
  • Ajax calls do not work in IE unless you fiddle with security settings
  • Keep this build forever option - Jenkins
  • How to use RequestBodyAdvice
  • Alert pop up with LWUIT
  • Xamarin Forms - UWP Fonts
  • Array.prototype.includes - not transformed with babel
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Spray.io: When (not) to use non-blocking route handling?
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Modifying destination and filename of gulp-svg-sprite
  • How to show dropdown in excel using jrxml (jasper api)?
  • How can I estimate amount of memory left with calling System.gc()?
  • GridView Sorting works once only
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Hits per day in Google Big Query
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?