The following script is simpler and works better:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("input.mod_quiz-next-nav").on("focus", function(){ var r = confirm("Are you sure you want to go to the next page?\n• Click [OK] to go to the next page\n• Click [Cancel] to stay on this page"); if (r == true) { $("input.mod_quiz-next-nav").blur() $("input.mod_quiz-next-nav").click() } else { $("input.mod_quiz-next-nav").blur() }; }); }); </script>
You will find a second example with its XML on MoodleFormulas ↗.