Search code examples
javascriptxmlhttprequesttampermonkey

How do i click a button on a webpage different from the one i currently have open using javascript (Tampermonkey)


this is my first time here, so hi to everyone!

i recently started learning and practicing javascript, mostly writing scripts in Tampermonkey.

At one point i came across XmlHttpRequest and managed to retrieve a page in DOMstring and parse it to a DOM Tree, using the GET method.

Now i wonder if there's a way with XmlHttpRequest or any other way to interact with a page different than the one i currently have loaded.

So for example, i have 2 pages from the same domain and the pages are a part of a CMS. The first is a blank page with only a button included, the second page includes tools to review a new user account.

Is it possible to press the button in the blank page and make an interaction in the second. like, pressing an "approve user account" button?

I should add that i cannot change things server-side and the button is created for example, with Tampermonkey.

Thank you for any answer i receive and i hope i wasn't too vague with my question


Solution

  • It' not possible to interact with a page via XmlHttpRequest. What you can do, is to look, what happens, if you click the button. If something like an GET- or POST-request is started, you could directly call that request instead. An interaction between two sites is also possible if you load the page in an iframe, but it might be easier to run Tampermonkey on both pages and communicate between them with GM.setValue and GM.getValue.