在浏览器中自动单击脚本

时间:2014-07-12 08:15:58

标签: javascript

用户声称无需离开计算机即可运行此类脚本,即自动点击操作隐藏在浏览器中:

http://forum.dashnet.org/discussion/206/autoclickers/p2#Comment_8954

这可能吗?如果是这样,专家能否向我展示一些指示,以便我可以学习为此目的做一些脚本?

2 个答案:

答案 0 :(得分:2)

使用javascript调度和事件是一项非常简单的任务。

有关现代方法,请参阅MouseEvent

var clickMe = document.getElementById('clickMe');

clickMe.addEventListener('click', function() {
  console.log('I was clicked');
}, true);

setTimeout(function() {
  var event = new MouseEvent('click'),
    canceled = !clickMe.dispatchEvent(event);

  if (canceled) {
    console.log('Click event was canceled');
  }
}, 5000);
<div id="clickMe">Click Me</div>

5秒后输出

I was clicked 

答案 1 :(得分:0)

var clickMe = document.getElementById('clickMe');

clickMe.addEventListener('click', function() {
  console.log('I was clicked');
}, true);

setTimeout(function() {
  var event = new MouseEvent('click'),
    canceled = !clickMe.dispatchEvent(event);

  if (canceled) {
    console.log('Click event was canceled');
  }
}, 5000);
<div id="clickMe">Click Me</div>