以下是定期将HTTP GET发送到URL(此处为google.com)的java脚本(此处为7秒)。现在,当Java脚本以给定的间隔执行时,我需要检查用户是否已执行该操作(如Mousedown,Mousemove等),然后只需要发送HTTP请求。请让我知道方法/解决方案。
out.println("function bustOut(){");
out.println("var xhr = getXMLHttpRequest();");
out.println("xhr.open(\"GET\",\"http://www.google.com\", true);");
out.println("xhr.setRequestHeader(\"Content-Type\", \"application/x-www-form-urlencoded; charset=UTF-8\");");
// some where here i need to check for the event.For example - if user had performed the action (Mousedown, Mousemove etc ) then only send the HTTP request.
out.println("xhr.send();");
out.println("};");
out.println("</script></head> ");
out.println("<body onLoad=\"setInterval(function(){ bustOut();},7000);\"></body>");
这些操作(如Mousedown,Mousemove等)将在浏览器上执行