0

I am trying to develop a simple script that restrains if the user can or cannot leave fullscreen mode, based on password prompt. Its main objective is to avoid visitors of a museum using the interactive device for other purposes other than its primary goal, which is a browser app that teaches some things about the things exposed there, hence why I am trying to write this script in JS.

So I have created a simple code, which basically should listen to the event fullscreenchange and act based on that, but that's where I am facing my biggest problem: it apparently doesn't.

What it does basically is: - Check if fullscreenchange was called; - If it was, see if the user is trying to enter or leave fullscreen mode; - If the user is leaving fullscreen mode, ask them to enter a password; - If the password is incorrect, it should enable fullscreen mode again.

Take a look at what I have for now:

        document.addEventListener("fullscreenchange", function() {
            fullscreenchange();
        });

        document.addEventListener("mozfullscreenchange", function() {
            fullscreenchange();
        });

        document.addEventListener("webkitfullscreenchange", function() {
            fullscreenchange();
        });

        document.addEventListener("msfullscreenchange", function() {
            fullscreenchange();
        });

        function fullscreenchange() {
            var fullscreen = (window.fullScreen) || (window.innerWidth == screen.width && window.innerHeight == screen.height);
            if(!fullscreen) 
            {
                if(!passwordChecks()){
                    openFullscreen()
                    return;
                }
            }
        }

        function openFullscreen() {
            if (elem.requestFullscreen) {
            elem.requestFullscreen();
            } else if (elem.mozRequestFullScreen) { /* Firefox */
            elem.mozRequestFullScreen();
            } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
            elem.webkitRequestFullscreen();
            } else if (elem.msRequestFullscreen) { /* IE/Edge */
            elem.msRequestFullscreen();
            }
        }

        function passwordChecks(){
            var pass = prompt("Enter password to leave fullscreen:");

            if(pass == "leave123")
                return true;

            return false;
        }

The script doesn't return any errors on console (using DevTools from Chrome). But it also doesn't work, when you try to leave fullscreen, nothing happens, that's why I mentioned the fullscreenchange event is apparently not working.

Please let me know if there is any error in this code, and what can be done to achieve the final goal. It is simple, I hope, but I really need your help, guys.

Thank you.

  • 1
    Rather than trying to use JavaScript, launch the browser itself in kiosk mode. see [SU: Running latest Chrome for Windows in kiosk mode](https://superuser.com/q/716426/252695) – p.s.w.g Apr 17 '19 at 22:40
  • JavaScript can't do this, for security reasons. It would allow someone to create a website that traps you in a full-screen window. – Barmar Apr 17 '19 at 22:52
  • All browsers have Kiosk Mode exactly for this reason. – Barmar Apr 17 '19 at 22:53
  • fullscreenchange events do work, but only if the fullscreen mode is triggered by requestFullScreen : https://stackoverflow.com/questions/21103478/fullscreenchange-event-not-firing-in-chrome – Claytronicon Apr 17 '19 at 22:55

1 Answers1

0

Check this, it may be useful: https://medium.com/@andreas.schallwig/building-html5-kiosk-applications-with-vue-js-and-electron-c64ac928b59f. You just need to use the "kiosk" mode

Tiago Rangel
  • 1,159
  • 15
  • 29