views:

1120

answers:

5

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.

+4  A: 

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.

Bob
I'm not too worried about keeping honest people honest. It's the not so honest people that I am worried about. The focus question comes from a requirement to track if a student navigates away from the test site. I can only assume at that point they are surfing for the answer.
Mark
Or that they finished early and now they're checking their Gmail...
Telemachus
The only way you can track them is by installing a windows application. Once they leave your site by a new tab, process or what ever, they are completly on their own. I'd say ditch the requirement.
Bob
+2  A: 

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.

Jon
A: 

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.

John Saunders
A: 

JavaScript has the capabilities do this but it is disabled by default in most modern webbrowsers (And, as you would surely agree, there was a good reason for that!)

Hippo
+1  A: 

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.

eyelidlessness
+1 to "finding another solution" especially because users can open up another browser to look up answers and you'll never be able to identify when they do.
Pras