我会尽量简明扼要。
我是一名教师,我们现在都在网上教学。上学期我在网上作业系统中发现了一批作弊的学生,我知道这是因为我拒绝使用Proctorio (这是非常具有侵入性的)。
我想要的(就我的能力而言),在这个在线作业系统中的问题中,我想知道学生什么时候离开了数字作业。在一些优秀的人的帮助下,我离这里越来越近了,不过,我还有更多的路要走。
这是修改过的代码。事件侦听器可以正常工作,但我想按下页面上的单个按钮,它就是不能工作。该按钮没有ID或名称,但innerHTML总是“提交问题”。
<script type="text/javascript">
var myWindow
window.addEventListener("blur", function(){
refocusWindow();
})
window.addEventListener("focus", function(){
myWindow.removeEventListener("blur", refocus);
myWindow.close();
})
function refocusWindow(){
myWindow = window.open("", "myWindow");
myWindow.document.write("<h1>During this assessment, you are not allowed any resources other than what is provided within the assessment. Going to another website, tab, page, or application is considered cheating. This event has been logged. Return to the assessment at this time or further actions will be taken!</h1>");
myWindow.addEventListener("blur", refocus);
}
function refocus(){
myWindow.close();
setTimeout(function(){
if (document.visibilityState != "visible" || document.hidden){
refocusWindow();
}
},1)
}
function clickButton() {
var buttons = document.getElementsByClassName("primary");
for(var i = 0; i < buttons.length; i++) {
if(buttons[i].type == 'button' && buttons[i].innerHTML == " Submit Question ") {
buttons[i].click();
break;
}
}
}
</script>按钮的类名是“主”,所以我要搜索它。
发布于 2021-01-09 14:16:21
您有几个选项(evercookies、server等),如果没有服务器,我能想到的最佳选择就是简单地防止用户离开选项卡。此外,您还可能需要添加一个系统,在关闭选项卡时将结果发送给您,因为如果不这样做,用户可以在知道问题的情况下关闭选项卡,然后作弊,然后输入答案。你也可以包括一个谷歌登录,以确保是学生在回答问题。
总之,说得够多了--以下是如何阻止他们离开网站的方法。请注意,这在在线文本编辑器上可能不起作用,因此您必须在计算机上创建HTML文件,复制并粘贴代码,然后在浏览器上本地打开它(如果使用windows,则从文件资源管理器中拖动文件,或者根据使用的内容从其他地方拖动文件)。要查看它的工作,只需离开选项卡。
<!DOCTYPE html>
<html>
<body>
Enter your name: <input type="text" id="fname">
<p>When you leave the input field, a function is triggered which transforms the input text to upper case.</p>
<script>
var myWindow
window.addEventListener("blur", function(){
refocusWindow()
})
window.addEventListener("focus", function(){
myWindow.removeEventListener("blur", refocus)
myWindow.close()
})
function refocusWindow(){
myWindow=window.open("", "myWindow")
myWindow.document.write("<h1>Please return to the HW - no cheating!</h1>")
myWindow.addEventListener("blur", refocus)
}
function refocus(){
myWindow.close()
setTimeout(function(){
if (document.hidden){
refocusWindow()
}
},1)
}
</script>
</body>
</html>请注意,您还可以集成全屏模式,这将使用户在触发keydown或click/mousedown/mouseup时进入全屏模式。
此外,可以缩短代码的一部分以使其更简洁。代之以:
var buttons = document.getElementsByClassName("primary");
for(var i = 0; i < buttons.length; i++) {
if(buttons[i].type == 'button' && buttons[i].innerHTML == " Submit Question ") {
buttons[i].click();
break;
}
}在这方面:
[...document.querySelectorAll("button.primary")].some(function(element){if(element.innerHTML===" Submit Question "){element.click(); return true}})查询选择器选择一个具有类主值的按钮,将HTMLCollection转换为列表,.some循环遍历元素,直到它用“提交问题”的innerHTML到达元素,然后单击它。在此之后,它返回true,这样它就停止了,并且不会遍历其余的部分。
[...document.querySelectorAll("button.primary")].some(function(element){if(element.innerHTML===" Submit Question "){element.click(); return true}})<button class="primary">Don't select</button>
<button class="primary" onclick="alert(1)"> Submit Question </button>
<button class="primary" onclick="alert(1)"> Submit Question </button> <!--Don't select-->
<!--The bottom isn't selected, as there is only 1 alert.-->
https://stackoverflow.com/questions/65639275
复制相似问题