如何使用 jquery 将文本从一个页面复制并粘贴到另一个页面?

发布于 2024-10-09 18:27:17 字数 207 浏览 0 评论 0原文

我必须将数据(联系信息,如姓名、电话...)从表单 A(域 x.com 中的第 1 页)重复复制到表单 B(域 y.com 中的第 2 页)

我一直在考虑创建借助 jquery 的 chrome 扩展从表单 A 复制数据,然后将其注入表单 B...

我有一种感觉,这不是解决这个问题的最佳方法...

您认为最好的方法是什么从不同域的页面复制和粘贴数据?

I have to copy repeatedly data (contact info such as name, surname, telephone...) from form A (page 1 in domain x.com) to form B (page 2 in domain y.com)

I have been thinking about creating a chrome extension with the help of jquery to copy the data from form A, and inject it form B...

I have a feeling that this is not the best way to solve this problem...

What do you think is the best way to copy and paste data from pages in different domains?

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

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

发布评论

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

评论(3

酷到爆炸 2024-10-16 18:27:17

我不是 Web 开发人员,但我认为在纯 JavaScript 中执行此操作是不可能的(请参阅 同源策略)。

您可能最好在服务器级别编写一些代码来处理此问题,也许在 x.com 上创建一个与 y.com 通信的代理 Web 服务做你需要做的事。但是在 x.com 上运行的客户端 JavaScript 不应该真正了解 y.com。

编辑:

啊,现在我明白了;我以为您正在编写一个供每个人使用的 Web 应用程序。如果这是个人的事情,只有您需要功能,那么我可能建议编写一个 Firefox Greasemonkey 脚本注入到您的 x.com 代码中,因为 Greasemonkey 确实允许跨站点 XMLHttpRequests (Ajax)。这将允许您从 x.com Greasemonkey Javascript 调用在 y.com 上运行的 Web 服务。我确信您可以使用您提到的 Chrome 扩展程序实现相同的目标。

I'm not a web developer, but I think doing this in pure JavaScript shouldn't be possible (see same origin policy).

You're probably better off coding something at the server level to handle this, perhaps making a proxy web service on x.com that talks to y.com to do what you need. But the client-side JavaScript running on x.com shouldn't really know about y.com.

EDIT:

Ah now I see; I was thinking that you were coding a Web application for everyone to use. If this is something personal that only you need functionality for, then I might recommend writing a Firefox Greasemonkey script to inject into your x.com code, as Greasemonkey does allow cross-site XMLHttpRequests (Ajax). This would allow you to call a web service running on y.com from your x.com Greasemonkey Javascript. I'm sure you could achieve the same thing using a Chrome extension as you mentioned.

寂寞笑我太脆弱 2024-10-16 18:27:17

您是否尝试过表单自动填充功能

Have you tried the Form Autofill feature?

情定在深秋 2024-10-16 18:27:17

取决于您的目标浏览器是什么。您也许可以使用一些持久存储 api。有一些很好的包装器可以抽象跨浏览器问题。

但你有尺寸限制。并且可能存在跨域问题。

depends on what your target browsers are. you MAY be able to use some persistent storage api. there are some good wrappers that will abstract the cross browser issues.

but you have size constraints. and may have cross domain issues.

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