c# - How can I make the beforeunload event fire only when a browser session is exited -


disclaimer - should note javascript pretty weak.

i'm in process of inserting code website can cover scenario when user exits browser, gets prompted proverbial 'are sure want quit?' sort of confirmation messsage.

i'm in process of trying implement piece of javascript on website:

   <script language="javascript" type0"text/javascript">  var foo = true;  window.onbeforeunload = askbeforeexiting;  function askbeforeexiting() {   if (foo)     return "are sure want leave page?"; } </script> 

the code not throws confirmation message when attempts exit browser made. however, throws confirmation when link portion of site clicked , other related events.

is there way modify code capture browser closing scenarios only? scenario killing browser task manager or powershell command can't captured. want scenarios in current user session may exit browser.

i've been looking on various samples across web , through code references , can't seem track down want do. possible?

i've done before page has form, , want ask user confirmation when change has been made form. similar, attach click event links, example, set foo false. like:

var links = document.getelementsbytagname('a'); for(var = 0, l = links.length; < l; i++) {     links[i].onclick = function () {         foo = false;     } } 

edit: there many other actions might have account for, depending upon site, information given, should start there no direct way accomplish after.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -