Javascript to detect if user changes tab

后端 未结 5 1848
无人共我
无人共我 2020-11-30 22:46


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.

5条回答
  •  有刺的猬
    2020-11-30 23:40

    If you are targeting browsers that support it, you can use the Page Visibility API available in HTML5. It doesn't directly detect tab changes, per-say, but visibility changes. Which would include (but not limited to) tab changes.

    See https://developer.mozilla.org/en/DOM/Using_the_Page_Visibility_API

提交回复
热议问题