windows 如何强制浏览器窗口始终位于顶部和焦点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/722681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I force a browser window to always be on top and in focus
提问by Mark
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.
有没有办法强制浏览器窗口始终位于顶部和焦点?我正在处理一个项目,除了关闭浏览器窗口外,我需要将浏览器窗口放在顶部并始终处于焦点状态。我已经通过 javascript 尝试了一些东西,但没有成功保持窗口的焦点。
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.
我并不是要对用户采取这种强制措施。我正在开展一个实施在线测试的项目,我不希望用户切换到网络上查找答案。
回答by Bob
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.
您将需要在客户端计算机上安装一个 Windows 应用程序,这将强制浏览器位于顶部。这是唯一的方法。
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.
如果您使用的是 IE,您可以打开一个模态对话框,该对话框将始终位于顶部和焦点,但只有在该浏览器会话中,用户才能自由切换应用程序。
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.
编辑:如果您正在编写测试应用程序,老实说,您最好为每个问题设置合理的时间限制。试图阻止他们查找答案是毫无价值的。如果他们并排放置两台机器怎么办?如果他们旁边有他们的好友帮助回答问题会怎样。你将不得不在这个系统上使用荣誉系统。
回答by jgallant
This is not possible, as the application level focus is handled by the Windows operating system.
这是不可能的,因为应用程序级别的焦点是由 Windows 操作系统处理的。
You would need to alter the operating system in order to achieve this functionality.
您需要更改操作系统才能实现此功能。
回答by eyelidlessness
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.
举例来说,你可以检测到blur
该事件window
的活动,然后调查(focus
,click
,mousemove
,keypress
等)来确定“空闲”时间的用户。如果用户“空闲”的时间足够长,以至于去别处寻找答案,那么他们很可能是在“作弊”。否则,您可以简单地对问题施加时间限制,如果分配的时间用完,则跳过这些问题。
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.
您不能保证您的用户没有“作弊”。要么构建测试的“物理”规则,使“作弊”的机会最小化,要么构建测试本身,使“作弊”的后果较小。不要试图规避浏览器中内置的用户保护,这些保护禁止用户像操作任何其他应用程序一样操作浏览器。
回答by John Saunders
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 willbe yours, you can force it to stay on top, or anything else you like.
使用 Windows 窗体 WebBrowser 控件创建一个合理的 Web 浏览器曾经花了我 15 分钟。我建议您要求学生通过此自定义浏览器程序查看您的站点。由于这个计划真的会是你的,你可以迫使它留在上面,或者其他任何你喜欢。
回答by TheHippo
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!)
JavaScript
具有执行此操作的功能,但在大多数现代网络浏览器中默认禁用它(而且,您肯定会同意,这是有充分理由的!)