This is my fragment.
$(function() { setCountDown(0, 1, 0); a = Array(); $(window).bind('beforeunload', function() { if (a['endTime']) { return ("You are in the middle of a test"); } }); }); function setCountDown(hours, minutes, seconds) { $(".timer").removeClass("common_displayNone"); timerInterval = setInterval( function() { if (hours.toString().length == 1) { hours = "0" + hours; } if (minutes.toString().length == 1) { minutes = "0" + minutes; } if (seconds.toString().length == 1) { seconds = "0" + seconds; } if (seconds > 0) { seconds--; if (seconds.toString().length == 1) { seconds = "0" + seconds; } } else if (seconds == 0 && (minutes > 0)) { minutes = minutes - 1; seconds = 59; } else if (minutes == 0 && (hours > 0)) { hours = hours - 1; minutes = 59; } if (hours == 0 && minutes == 0 && seconds == 0) { clearInterval(timerInterval); a.removeItem("endTime"); } $("#timer").html(hours + ":" + minutes + ":" + seconds); a['endTime'] = (hours * 3600 + minutes * 60 + seconds); }, 1000); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="timer"></div>
Just try reloading the page. You will receive a warning. During this warning, my timers do not work. In this way, the user can trick the test. How to solve this problem?
I'm afraid that how it works alert. It blocks one thread of JavaScript running, waiting for input. I suggest warning in another way. Not only does this not block, but you can also style the real window with CSS.
alert
Javascript - , , "". javascript , , "".
, HTML CSS.
, , , javascript, . websockets .
JavaScript (*), , script, - , , .
Source: https://habr.com/ru/post/1629909/More articles:Java: creating a shadow effect on an image - javaError in binary reading - c #PHP: autoload problem - oopAsmack file transfer speed is always 0.0 - androidPHPStorm uses private key to sign commit - gitAndroid - EditText gives IndexOutOfBounds exception when writing something - androidWhat data structure in Python is used to replace Excel 2-dimensional array of strings / sums? - pythonRecursive loop of an array of arrays using functional - iosWhat is the use of having $ sce or Strict Contextual Escaping in angularjs and why is the reaction not needed? - javascriptHow to create a dataframe column with duplicate row value? - pythonAll Articles