I Have a chrome extension, it click a button when the page is loaded.

$(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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top