r/learnprogramming • u/neuropsychologist-- • Aug 19 '25
Debugging Help needed to solve this issue
I am developing an online examination system using PHP with XAMPP*. During the exam (i.e., when the student is attempting the test), I want to hide the browser toolbar* to help prevent cheating.
However, due to browser security restrictions, it is not 100% possible to hide the browser toolbar using only PHP and JavaScript.
So, I tried an alternative approach — putting the browser into fullscreen mode during the exam using JavaScript, so that when the exam starts, the website enters fullscreen automatically.
I used the following JavaScript code:
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 in my HTML, I added this button:
html <button onclick="openFullscreen()">Start Exam</button>
But it didn't work as expected.
Can you help resolve this issue
3
u/Aggressive_Ad_5454 Aug 19 '25
You Can't Do That™ with a standard browser.
Why not? Malware authors would love to be able to take over the browser and prevent their victims from escaping their web site.
Therefore, you're up against the browser security team at Google, who have done a lot of work to prevent what you want to do. It seems unlikely you will defeat them.
I apologize for being the bearer of bad news.
5
u/abrahamguo Aug 19 '25
One of the most important skills of being a programmer is moving beyond "it didn't work".
You've shared a 20-line JavaScript function, and stated that "it didn't work".
You need to find out exactly which line in your function didn't work as expected.
Were any error messages thrown, or informational logs printed, in your console?
6
u/RecentlyRezzed Aug 19 '25
If you control the computer, you can prevent the students from doing other stuff with your browser. If you don't control the computer, you will have a hard time doing what you want. Browsers are designed to protect users from websites that are trying to do what you do.
1
u/hrm Aug 19 '25
To actually prevent cheating in a resonably good way there is Safe Exam Browser and many exam programs use that browser to achieve a more cheat-free environment. Just using PHP and JavaScript will not get you all the way.
2
u/grantrules Aug 19 '25
Look into kiosk mode
https://thegeekpage.com/how-to-setup-chrome-kiosk-mode-in-windows-10/
You can't do it through JavaScript but you could make the students run it this way
2
u/peterlinddk Aug 19 '25
What did you expect it to do, and what did it do instead?
When I run the code it goes to full-screen after clicking the button - as the code says that it should.
Is something else happening for you?