IE8 加速器停止 JavaScript 计时器

发布于 2024-10-27 15:48:56 字数 1420 浏览 3 评论 0原文

我们有一个 asp 应用程序,人们可以在上面进行测试。在测试页上,有一个asp控件显示剩余时间。当您右键单击该控件时,提供时间的 JavaScript 将被中断。为了解决这个问题,我们禁用了右键单击。但现在我注意到,如果您选择一些文本并单击 IE8 加速器蓝色按钮,JavaScript 也会被中断。禁用左键单击当然是没有选择的。

我在 IE 中找到了一个禁用加速器的选项,所以对于我们内部来说,问题已经解决了。但我们希望找到另一种解决方案,因为我们不能要求每个用户在所有计算机上禁用该选项。

我们更喜欢在代码中集成修复程序的解决方案,以便通过升级程序来解决问题。因此,如果有人知道是否以及如何可以禁用/绕过/...即加速器...

提前致谢。

编辑

同时使用服务器上的计时器和客户端上的计时器会引发一个新问题:您将在哪里划定服务器和客户端上的时差之间的界限。不管怎样,这个问题到目前为止还没有发生,所以我猜人们太忙于专注于测试,然后寻找一种方法来破坏我们的系统。

编辑2

我尝试使用 onSelectStart 的方法,但没有成功。这是我的测试 html:

<html xmlns="http://www.w3.org/1999/xhtml" >
<SCRIPT LANGUAGE="JavaScript">
    function showObj() {
        //alert('?');
        return false;
    }
</SCRIPT>
<head>
    <title>Untitled Page</title>
</head>

<body onSelectStart="showObj()">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
        Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
        Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    </p>
</body>

We have an asp app on which people can take tests. On the test page, there is an asp control that shows the time remaining. When you right click that control, the javascript that provides the time is interrupted. To solve that, we disabled right-clicking. But now i've noticed that if you do a selection of some text and click the IE8 accelerator blue button, the javascript is also interrupted. Disabling the left-click is of course no option.

I've found an option in IE that disables the accelerator, so for us internally, the issue is solved. But we would like to find another solution, just because we cannot ask every one of our users to go disable that option on all their computers.

We prefer a solution that we integrate a fix in our code, so that the issue is resolved with an upgrade of our program. So if anyone knows if and how it is possible to disable/bypass/... Ie accelerator...

Thanks in advance.

Edit

Working with both a timer on the server and one on the client raises a new problem : where will you draw the line between the time difference on the server and the client. Anyway, this problem has not occured so far, so i guess people are too busy concentrating on the test then on finding a way to break down our system.

Edit 2

I tried using the method with onSelectStart, but no luck. This is my test html:

<html xmlns="http://www.w3.org/1999/xhtml" >
<SCRIPT LANGUAGE="JavaScript">
    function showObj() {
        //alert('?');
        return false;
    }
</SCRIPT>
<head>
    <title>Untitled Page</title>
</head>

<body onSelectStart="showObj()">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
        Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
        Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    </p>
</body>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

提笔书几行 2024-11-03 15:48:57

与验证相同,永远不信任来自客户端的数据。您真正应该做的是在服务器端记录测试开始的时间,然后记录测试提交的时间。用户端的时钟应该只是一个精确的时钟,而不是依赖,因为无法保证它是准确的(出于上面发布的六个原因)。

几乎无故障的方式是用户在服务器端获得最终用户无法以任何方式知道、交互或修改的东西。

Same as validation, never trust data that comes from the client. What you really should be doing is recording, on the server side, the time that the test started, and then the time that the test was submitted. The clock on the user side should only be a nicety, but not relied upon, as there's no way to guarantee that it's accurate (for half a dozens reasons posted above).

The nearly fault-proof way is the user something on the server-side that is not in any way known of, interacted with, or modifiable by the end user.

太阳男子 2024-11-03 15:48:57

解决方案是禁用选择文本的功能。听起来复制+粘贴在您正在工作的环境中并不是必需的。

在大多数浏览器中,这是使用 CSS 完成的: user-select: none; (带有浏览器前缀如适用)。

然而,这个 CSS 在 IE 中不可用(虽然我不确定 IE9,所以无论如何它可能值得包含),并且由于您专门询问 IE,因此您需要一个替代解决方案。幸运的是,IE 确实提供了一个:

<div unselectable="on">...</div>

不幸的是,该属性不是继承的,因此您需要在每个包含文本的元素上指定它。 (或者您可以编写一个 Javascript 或 JQuery 函数,在页面加载后将其应用于每个元素)

最后,可能是最好的选择:还有一个可以绑定到元素的 onselectstart 方法。像这样的事情会禁用文本选择: onselectstart = function(){ return false; }。更好的是,它应该由子标签继承,因此您可以将其放在 标签上并完成它。

The solution is to disable the ability to select text. It doesn't sound like copy+paste is going to be necessary in the environment you're working in.

In most browsers, this is done using CSS: user-select: none; (with browser prefixes as applicable).

However, this CSS isn't available in IE (I'm not sure about IE9 though, so it may be worth including anyway), and since you're specifically asking about IE, you need an alternative solution. Fortunately, IE does provide one:

<div unselectable="on">...</div>

Unfortunately, the attribute isn't inherited, so you'll need to specify it on every element that contains text. (or you could write a Javascript or JQuery function that applies it to every element once the page has loaded)

Finally, and possibly the best option: There's also a onselectstart method which can be tied to an element. Something like this would disable text selection: onselectstart = function(){ return false; }. Even better, that should be inherited by child tags, so you could just put it on your <body> tag and be done with it.

无名指的心愿 2024-11-03 15:48:56

如果您使用完全基于客户端的计时器来实际验证人们在特定时间内提交了某些内容,那么作弊总是有可能的。有人可以将一个脚本放在您的页面顶部,从而完全终止计时器,无论您做什么。

看来你应该使用服务器时钟。如果某个客户的行为破坏了屏幕计时器,那么您对此无能为力。但只要您在人们提交答案时验证服务器上的时间,它就总是准确的。

If you are using a completely client-based timer to actually validate that people submit something in a certain time, cheating will always be possible. Someone can just drop a script on top of your page that kills the timer entirely, no matter what you do.

Seems that you should be using a server clock. If some customer does something that breaks an onscreen timer, well, there's nothing you can do about that. But as long as you validate the time on the server when people submit an answer, it will always be accurate.

孤寂小茶 2024-11-03 15:48:56

查看这篇文章:

禁用整个网站的 IE8 加速器

@EricLaw说不,您不能为网站禁用它们。

@mbenny 说您可以将内容标记为 contentEditableunselectable

Check out this post:

Disabling IE8 accelerators for an entire site

@EricLaw says no, you can't disable them for a site.

@mbenny says that you can mark content as contentEditable or unselectable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文