简体   繁体   English

jQuery按钮在页面加载时单击,是否不断循环?

[英]jQuery button click when page load, keeps looping?

I Have a chrome extension, it click a button when the page is loaded. 我有一个chrome扩展程序,它在页面加载时单击一个按钮。

$(document).ready(function(){
      document.querySelectorAll("input[type='submit']")[0].click(); 
});

This works, the only problem is that the button is also on the next page. 这可行,唯一的问题是该按钮也在下一页上。 So it keeps pressing the button and the page keeps reloading, so it's in a loop. 因此,它一直按下按钮,页面不断重新加载,因此处于循环中。

How do I fix this? 我该如何解决?

One solution would be to refine your selector. 一种解决方案是优化选择器。 Find an unique parent element for the page you're targeting and create a more specific selector. 在您要定位的页面中找到唯一的父元素,然后创建一个更具体的选择器。

Another solution would be to check the current page url or the referrer and see if it matches a certain pattern. 另一个解决方案是检查当前页面的URL或引荐来源网址,并查看其是否与特定模式匹配。

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

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