Create a web project in Visual Studio 2013, remove all scripts (which could interfere) and add this:
<script type="text/javascript" src="~/Scripts/jquery-1.8.2.min.js"></script> <!-- Note that the version might be different -->
<script type="text/javascript">
jQuery(window).bind('beforeunload', function (e) {
var message = "Why are you leaving?";
e.returnValue = message;
return message;
});
</script>
The onbeforeunload
event won't fire. However if you open this with Visual Studio 2012 it will work (note that to open it with Visual Studio 2012 you shouldn't use ASP.NET MVC 5
).