简体   繁体   中英

How do you write Javascript to open page and then click on button on page in one go

I would like to open a particular webpage and then click on a button to open another page from that page. Now I can see how to write Javascript to find a button on page and click on it, what I dont quite understand how I can do that from the 1st page.

ie on Page 1 can open Page 2, but how do I in one go from page 1 get it to click on a button on page 2 once page 2 is loaded because until Page 2 is loaded the button is not available, and if I just go to Page 2 my Javascript will not be running because that was on Page 1?

What I am trying to do is a poweruser feature that makes it easier to do a particular repetitive task, I am the sys adminstator for page 1 but not page 2.

This is example of the page Im trying to do this for

https://acoustid.org/track/61c9656b-6838-4660-8113-86f7f90fd549

You need to login to Acoustid to actually see the Disable buttons

Open new browser window with js (modal or tab)

var newWindow = window.open("http://www.....com");

Add onload handler for new window and insert script (optionally)

newWindow.addEventListener("DOMContentLoaded", Func);

function Func()
{
    var script = newWindow.document.createElement("script");
    script.text = "alert('hello');";
    newWindow.document.body.appendChild(script);
}

Insert js code straightforwardly if you don't need to handle load

Func();

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