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
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")
}
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
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
Fine and always welcome Aparna!!!
It works Murali. I will surely ask you if i get any doubts in future also.
Thanks again
Sure Aparna.
It's my pleasure