I need a confirmation pop up on browser close.I am using onbeforeunload event but not working in Firefox also want to restrict pop up on page refresh
<p>I need a confirmation pop up on browser close. I amm using <code>onbeforeunload</code> event but not working in Firefox also the pop up comes whenever the page refreshed which I want to restrict.</p>

<pre><code>window.onbeforeunload = DetectBrowserExit;

function DetectBrowserExit() {
return 'Are you sure to exit';`enter code here`
}
</code></pre>