[英]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.我最近开始学习和练习 javascript,主要是用 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.有一次,我遇到了 XmlHttpRequest 并设法在 DOMstring 中检索页面并将其解析为 DOM 树,使用 GET 方法。
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.现在我想知道是否有一种方法可以使用 XmlHttpRequest 或任何其他方式与与我当前加载的页面不同的页面进行交互。
So for example, i have 2 pages from the same domain and the pages are a part of a CMS.例如,我有来自同一个域的 2 个页面,这些页面是 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.我应该补充一点,我无法更改服务器端的内容,并且例如使用 Tampermonkey 创建按钮。
Thank you for any answer i receive and i hope i wasn't too vague with my question感谢您对我的任何回答,我希望我的问题不会太含糊
It' not possible to interact with a page via XmlHttpRequest.无法通过 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.
如果启动了 GET 或 POST 请求之类的东西,您可以直接调用该请求。 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.
如果您在 iframe 中加载页面,则两个站点之间的交互也是可能的,但在两个页面上运行 Tampermonkey 并在它们之间使用 GM.setValue 和 GM.getValue 进行通信可能会更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.