如何在Chrome扩展程序中添加自动点击功能? [英] How to add automatic click feature in chrome extension?
本文介绍了如何在Chrome扩展程序中添加自动点击功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建Chrome扩展程序,需要自动点击第一个链接一段时间。
可以在chrome扩展中添加自动点击功能吗
I am creating a chrome extension, and need to click on the first link automatically for some time. Is it possible to add automatic click feature in chrome extension??
推荐答案
如果你不在乎鼠标坐标,可以使用:
If you don't care about mouse coordinates, you can use this:
var trigger = document.createEvent("Event");
trigger.initEvent("click", true, true);
element.dispatchEvent(trigger);
<如果你还想指定一个特定的X / Y坐标,你可以使用:
"element" should be the DOM node you want to trigger the click on. If you want to also specify a particular X/Y coordinate, you could use this:
var x = 0,
y = 0;
var trigger = document.createEvent("MouseEvent");
trigger.initMouseEvent("click", true, true, null, 0, x, y, x, y, false, false, false, false, 0, null);
element.dispatchEvent(trigger);
更改 x
和 y
到你想要的...或者只是使用jQuery,比如npdoty说。
Change x
and y
to what you want ...or just use jQuery, like npdoty said.
这篇关于如何在Chrome扩展程序中添加自动点击功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文