15
Views
5
Comments
Solved
Quiz application with security measures

Hi all

I have a task on creating a quiz application. Help me to achieve this scenario 

In this whenever the quiz starts , screen needs to turn into full screen.

If the user exits full screen or presses windows, alt or tab key quiz needs to be closed.

Kindly help me with this scenario on how to achieve this logic

2024-05-02 09-49-04
Murali Manoharan V
Champion
Solution

Hi Aparna

For that you need to use custom JS to implement this scenario.

For implementing full screen when quiz starts, use this JS

document.querySelector("body").requestFullscreen({ navigationUI: "show" })

.then(function() {

})

.catch(function(error) {    

});

To close the quiz on exiting full screen or pressing alt or win key use this js script

document.onkeydown = function (e) {        

          if(e.altKey)

            document.getElementById('press1').click();

         if (e.key == "Meta")

            document.getElementById('press1').click();                

}

          if (document.addEventListener){ 

             document.addEventListener('fullscreenchange', exitHandler, false);                 

             document.addEventListener('mozfullscreenchange', exitHandler, false); 

             document.addEventListener('MSFullscreenChange', exitHandler, false); 

             document.addEventListener('webkitfullscreenchange', exitHandler, false);

}

function exitHandler(){ 

             if (!document.webkitIsFullScreen && !document.mozFullScreen && !document.msFullscreenElement) 

{  // Run code on exit    document.getElementById('press1').click(); //Action to be execute on violating terms like exit fulscreen

}}


If hope it will work for you

Regards

Murali

UserImage.jpg
Aparna Mishra

Hi Murali

Thanks a lot for your help. I will use this code in my application, if i got any questions, I will reach you back

2024-05-02 09-49-04
Murali Manoharan V
Champion
UserImage.jpg
Aparna Mishra

It works Murali. I will surely ask you if i get any doubts in future also.

Thanks again

2024-05-02 09-49-04
Murali Manoharan V
Champion
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.