简体   繁体   English

javascript每5秒点击一次链接

[英]javascript to click a link every 5 seconds

I need a javascript routine that will click a link every n seconds until interrupted. 我需要一个JavaScript例程,该例程每隔n秒单击一次链接,直到被中断。 I did find a routine that clicked a button but I don't know how to point the function to a link rather than a .button. 我确实找到了单击按钮的例程,但是我不知道如何将函数指向链接而不是.button。

Thanks, Wayne 谢谢,韦恩

Assuming you're actually trying to click a link that doesn't navigate to another page (what you asked, I suppose), you would probably use jQuery: 假设您实际上是在尝试单击无法导航到另一个页面的链接(我想您所询问的),那么您可能会使用jQuery:

var variableToCancelInterval = setInterval(function(){
  $("a.linkclass").click();
}, 5000);

If you want to trigger anchor as a click so you can use simulate function, jQuery team create this function which will support in in Chrome, Firefox, Opera and IE10. 如果您想触发锚点单击以使用模拟功能,则jQuery团队会创建此功能,该功能将在Chrome,Firefox,Opera和IE10中支持。

so first you have to download this script for using simulate function after jQuery script. 因此,首先您必须下载此脚本,以便在jQuery脚本之后使用模拟功能。 Here is a link and example: 这是一个链接和示例:

$('a').simulate('click');

jquery.simulate.js jquery.simulate.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM