Search code examples
reactjsstackfullscreenanti-cheat

ReactJS Show alert when user leaves the current browser tab


I would like to lock users on the page. The users can go on other tabs or desktop at least when they click on other tab of browser I would like to show them alert dialog which say "Are you sure?"


Solution

  • Hi guys Thanks for helping

    I find code which is I need :

      requestFullscreen = () => {
        if (!document.fullscreenElement) {
          document.documentElement.requestFullscreen();
        } else if (document.exitFullscreen) {
          document.exitFullscreen();
        }
      };
    

    then I called this function onClick event on Button. After that I will check when User try to left page (alt+f4, alt+tab .. etc) I will show alert for "Are you sure for left page "