I'm working on an online examination system using PHP and XAMPP, and I've hit a roadblock. I want to automatically enter fullscreen mode when a student starts an exam to prevent them from accessing other browser tabs. I attempted to use a JavaScript function that I found, but it hasn't worked as expected. Here's the code I used:
```javascript
function openFullscreen() {
const elem = document.documentElement;
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();
}
}
```
And I added a button in my HTML to trigger it:
```html
```
Unfortunately, this isn't functioning as I anticipated. Any tips on how I can solve this issue?
3 Answers
Just saying 'it didn't work' isn't enough. You need to debug and find out which part of your script is failing. Check your console for any error messages or logs that can help pinpoint the issue.
If you have control over the computer, you can restrict students from navigating away from the exam page. But if that's not the case, keep in mind that browser security is designed to prevent sites from doing exactly what you're trying to do. It might be tough to fully achieve what you want without extra tools or permissions.
To effectively prevent cheating, consider using a dedicated tool like Safe Exam Browser, which many educational programs rely on for secure testing. Relying solely on PHP and JavaScript might not be sufficient for preventing dishonest behavior.
Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically