I want to write a webpage for online quiz.Basic requirement i have is that, If the person taking quiz changes tab or opens new window even without minimizing browser, i.e if the person tries to see the answer from some other window/tab, quiz should stop.How can i do that?<br>.I want to write a webpage for online quiz.Basic requirements i have is that, if the person taking quiz changes tab or opens new window even without minimizing browser, i.e if the person tries to see the answer from some other window/tab, quiz should stop;
追伸:HTML5の新しい機能ではなく、現在の主要なブラウザでサポートされている必要があります。
タブやウィンドウがアクティブかどうかは、blur / focusイベントリスナーをwindowにアタッチすることで判断することができます。
jQueryでは、次のようになります。
$(window).focus(function() {
//do something
});
$(window).blur(function() {
//do something
});
このSOの回答から引用: https://stackoverflow.com/a/1760268/680578