javascript - In jQuery, show alerts when user try to change tab or change windows -


i want make exam page, , not let user visiting other pages until submits it.

it seems onunload , onbeforeunload cases user explicitly close page. wondering if there trigger event when page lose focus.

you can use $(window).blur() event that.

$(window).blur(function() {     console.log("page left"); }); 

or better page visibility check can find here: https://developer.mozilla.org/en-us/docs/web/guide/user_experience/using_the_page_visibility_api

however, when show alert, won't able keep on page. can checkbox alert not show again. notify them test auto submit if leave tab won't want.

$(window).blur(function() {     if(!confirm("notice leaving page")) {         if(!document.hasfocus()) {             console.log("user left page");         }     } }); 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -