简体   繁体   中英

How can I run javascript on similar pages?

I want to use chrome snippet to run a javascript code to autofill a series of pages.

The problem is after another page was opened, the code seems stopped.

Instead, I need it run continually. Like this:

 //Page 1 form
 document.getElementById('page1Radiobutton').click()
 //Click Next
 document.getElementById('page1Next').click()
 //Page 2 form (need run continually after page 1 was submitted, but now stop at here...)
 document.getElementById('page2Radiobutton').click()
 document.getElementById('page2Next').click()

Your JavaScript can't really run across pages. Once the user navigates to a new page, all JavaScript is thrown out by the browser for security (among other) reasons.

I would look into browser extensions such as Tampermonkey (for Chrome) or Greasemonkey (for Firefox)

With either of these monkeys, you can create snippets of arbitrary javascript that will run on any page on the internet automatically.

If you are going to create a script that runs on every page, make sure it exits gracefully if it can't find the elements you're looking for. Otherwise you'll end up with javascript errors when you go to other pages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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