I've written a code which displays the list of quizzes and when one is selected a new window is popped up and the online quiz runs. 问题是,当窗口关闭时,计时器应该到期,即表单应该在窗口关闭之前提交。生成新窗口的代码如下:
var radios = document.getElementsByName("quizname");
var flag=0;
for (var i = 0; i < radios.length; i++)
{
if (radios[i].checked)
{
flag=1;
var x=radios[i].value;
var z=radios[i].value;
break;
}
}
if(flag==0)
{
alert("Choose an option!!");
exit;
}
var x="http://127.0.0.1/example/timedrunquiz.php?y="+x;
var win=window.open(x,z,"fullscreen=yes,scrollbars=yes");
win.focus();
我用过win.onbeforeunload
,但我无法完成任务。我应该怎么做才能在关闭前提交表格?提前致谢!