-2

how to prevent a user close/leave a browser windows using javascript/jquery..

If user open my web page then he can not close or minimizes or move to other window..

how to do this using javascript or Jquery

  • 3
    Possible duplicate of [how to block users from closing a window in javascript?](http://stackoverflow.com/questions/2229942/how-to-block-users-from-closing-a-window-in-javascript) – Mursaleen Ahmad Jul 21 '16 at 04:49
  • 1
    i dont want to say this is user friendly. can you rethink about doing this on your web page. your user might get annoyed about this – guradio Jul 21 '16 at 04:50
  • This also has the answer to your question http://stackoverflow.com/questions/3888902/javascript-detect-browser-close-tab-close-browser – Abhilash R Vankayala Jul 21 '16 at 04:50

1 Answers1

4

You can try this :

<script>
window.onbeforeunload = PopUpExit;
function PopUpExit() {
    return "You want to leave this page?";
}
</script>

Here is the code if you need only alert without text :

Javascript :

window.onbeforeunload = function(){
return '';
};

Jquery :

$(window).bind('beforeunload', function(){
return '';
});
Manjuboyz
  • 6,978
  • 3
  • 21
  • 43