Answers and code snippets from ASP.NET projects (Webforms/MVC/Classic ASP)
window.onbeforeunload = function(e) { return 'Dialog text here.'; };