How do I force a browser window to always be on top and in focus

11,822

Solution 1

You will need to install a windows application on the clients machine which will force the browser to be on top. This is the only way.

If you are using IE, you can open a Modal dialog which will always be on top and in focus but only while in that browser session, the user is free to switch applications.

Edit: If you are writing a testing application, you are honestly better off just putting a reasonable time limit on each question. trying to prevent them from looking up the answers is worthless. What if they have two machines side by side? What if they have their buddy next to them helping with the answers. You are going to have to go with the honor system on this one.

Solution 2

This is not possible, as the application level focus is handled by the Windows operating system.

You would need to alter the operating system in order to achieve this functionality.

Solution 3

I commented on the question, but realized this is worth posting as an answer...

Find another solution. Think a little about it. If a user is off looking at answers in another window/tab/browser, what would be the side-effects of that? Detect those side-effects, and penalize/block in those cases.

For instance, you can detect the blur event on the window and then poll for activity (focus, click, mousemove, keypress and so on) to determine "idle" time for the user. If the user is "idle" long enough to have gone elsewhere to find an answer, they are more than likely "cheating". You can otherwise simply impose time constraints on questions, and skip those questions if the time allotted runs out.

You can't guarantee that your user is not "cheating". Either construct the "physical" rules of the test such that the chance of "cheating" is minimized, or construct the test itself so that "cheating" is less consequential. Do not try to circumvent in-built user protections in browsers that disallow users from operating their browser as they would any other application.

Solution 4

The browser window belongs to the browser, not to you. Don't screw around with it.

Don't do it, that is, unless you wrote the browser.

It once took me 15 minutes to create a reasonable web browser by using the Windows Forms WebBrowser control. I suggest you require the students to view your site through this custom browser program. Since this program really will be yours, you can force it to stay on top, or anything else you like.

Share:
11,822
Mark
Author by

Mark

Updated on June 05, 2022

Comments

  • Mark
    Mark almost 2 years

    Is there a way to force a browser window to always be on top and in focus? I am working on a project that I need to have the browser window on top and in focus all the time except when closing the browser window. I have tried a few things through javascript, but have not had any success keeping the window in focus.

    I am not trying to do this to be forceful to the user. I am working on a project to implement online testing and I don't want the user to be able to switch away to look up answers on the web.