最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I force a browser window to always be on top and in focus - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited Apr 6, 2009 at 18:53 Mark asked Apr 6, 2009 at 18:48 MarkMark 1,3765 gold badges13 silver badges26 bronze badges 7
  • 1 As a browser user, I would say "You don't. That's abusive." The user gets to decide what's on top and in focus. – Telemachus Commented Apr 6, 2009 at 18:51
  • 1 I agree with Telemachus. What happens if two apps decide they always need to be on top and in focus. I can tell you from experience - they take up all the machine's CPU cycles fighting with each other, and you can't do anything. – Paul Tomblin Commented Apr 6, 2009 at 18:54
  • 1 If you figure this out, please forward it to the IE, Opera, FF, Chrome and all other browser teams so they can plug that particular hole. Then, jump in a fire. – user1228 Commented Apr 6, 2009 at 19:01
  • Surely, if you're doing this to prevent users looking away you are being definitely forceful. If you don't trust your users (and who does?) you need to pensate through other means. – David Thomas Commented Apr 7, 2009 at 0:33
  • 1 So how do you plan to prevent your users looking up the answers in a book? – Blorgbeard Commented Apr 7, 2009 at 7:24
 |  Show 2 more ments

5 Answers 5

Reset to default 7

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.

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.

I mented 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.

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.

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!)

发布评论

评论列表(0)

  1. 暂无评论