跨选项卡复制数据

发布于 2024-08-25 05:08:25 字数 294 浏览 2 评论 0原文

我在两个不同的选项卡中得到了两种不同的表格。一个包含来自我们系统的数据,另一个是另一个外部系统的接口,我们需要将数据复制到其中(XML 或 API 集成不是这里的选项)。

这就是说,以两种不同的方式打开这两种形式选项卡 - 我需要一个greasemonkey脚本或类似的东西,允许我将数据从一种表单复制到另一种表单(使用Javascript中的getValue方法)。

现在的问题是,我无法弄清楚如何使用greasemonkey脚本引用一个特定的选项卡或窗口(从中读取数据或向其中写入数据)。你认为有可能做我想做的事吗?

谢谢

I got two different forms in two different tabs. One has data from our system and the other one is an interface of another, external, system in wich we need to copy data into (XML or API integration not an option here)

The this is that, having open both forms - in two different tabs - i need a greasemonkey script or something similar that allows my to copy data from one form to the other (using the getValue method in Javascript).

The problem right now is that I cannot figure out how to reference with a greasemonkey script one particular tab or window (to rad data from or write data to). Do you think it would be possible to do what I'm thinking to do?

THANKS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

堇年纸鸢 2024-09-01 05:08:25

是的,我相信这是可能的。 Greasemonkey 存储的配置值按脚本存储,因此您需要确保您的单个 Greasemonkey 脚本针对这两个页面运行,即使它们位于不同的 URL。 (更多信息。)

您可能需要一个大的 if/else 块来将要在源页面和目标页面上运行的代码分开,如下所示:

if (window.location.hostname.match(/source-site\.com/) {
    //attach to the form fields and make them call GM_setValue() on every change
} else if (window.location.hostname.match(/target-site\.com/) {
    //use GM_getValue() to pull in the data you stored from the source site
}

这似乎比在一页上执行脚本并尝试访问其他打开的窗口的 DOM 更容易(我不是当然是可能的)。

Yes, I believe it's possible. Greasemonkey stored configuration values are stored per script so you need to make sure that your single Greasemonkey script runs against both of those pages, even if they're at different URLs. (More info here.)

You're probably going to want a large if/else block to divide up the code you want to run on the source page and on the target page, with something like this:

if (window.location.hostname.match(/source-site\.com/) {
    //attach to the form fields and make them call GM_setValue() on every change
} else if (window.location.hostname.match(/target-site\.com/) {
    //use GM_getValue() to pull in the data you stored from the source site
}

This seems easier than having the script execute on one page and try to access the DOM of other open windows (which I'm not sure is possible).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文