Is it possible to close the browser window using jQuery? I tried this:
$(document.ready(function() { $(window).unload(function(e) { e.preventDefault(); alert("Not closing"); }); });
The warning works, but the window closes anyway.
Fortunately, this is not possible!
You can display a confirmation dialog with onbeforeunload(see, for example, here , how to do this), allowing the user not to leave the page at the end, but you cannot prevent closing against the user.
onbeforeunload
This would be a huge security issue, and although I never had to personally investigate it, I doubt that any browser will allow you to close the window.
This will be a fundamental violation of user autonomy.! How do you like it if the site forbids you to close your browser?
It is best to show a confirmation dialog, as Pekka suggests; you can ask them if they are sure, but ultimately their decision if they want to close it!
as other answers say that it is impossible to prevent, but you can give the user the opportunity to choose. Maybe you are looking for this ...
How can I override the OnBeforeUnload dialog and replace it with my own?
Source: https://habr.com/ru/post/1776486/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1776481/aspnet-mvc-unit-tests-fake-repository-has-become-unwieldy&usg=ALkJrhiSrwnbwJ5Yzglf_Ix9ck70WE4-1QHow to send a PUT request under Windows using curl? - command-lineHow to convert a BufferedImage to an image? - javaHow to pass dev_appserver parameters for django-nerel - google-app-engineКаковы различия между базами данных NoSQL и чем они отличаются от традиционных реляционных баз данных? - databaseHow to prevent jquery event from triggering in dropdown list provided that event is connected - jqueryHow useful are delegates? - jqueryProblem launching a UNIX shell script from an Oracle parallel program - unixPHP GIF / PNG True Colorize Filter that preserves brightness and alpha - phpСтатус обратного вызова запроса "textStatus" - jqueryAll Articles