如何在跨域导航期间提供数据

发布于 2025-02-06 18:34:31 字数 700 浏览 3 评论 0原文

我想知道在浏览器中页面之间的跨域导航期间提供数据的选项以及是否有任何共同的做法。

作为我现在面临的示例:

说我在https://pagea.com时,当用户单击某些链接时,我想显示另一个页面https:// pageb.com托管在另一个域上。因此,我想为b提供一些其他信息,在加载过程中可以使用。从字面上看,它可以是a具有:用户名,地址,主题等的任何数据...提供。

我知道的解决方案之一是将这些数据放入查询参数中,以便导航URL看起来像:https://pageb.com?username = ....... address=...Address=....。amp.amp; theme=。 。但是,如果有很多数据,则无法使用。

我知道的另一个解决方案是将数据临时存储在服务器上:a a向服务器发表请求,服务器将数据存储在某个地方,并返回可用于获取数据的密钥。我导航到页面b在查询参数中提供键 - https://pageb.com?key= {key}b b 应该使用该密钥从服务器获取数据。对于我的例子来说,这似乎是一个可以的解决方案。

但是我想知道是否还有其他解决方案?当提供大量数据时,有什么共同的做法?

提前致谢!

I'd like to know what are the options for providing data during cross-domain navigation between pages in browser and if there's any common practice for that.

As an example of what I'm facing right now:

Say I'm on https://PageA.com and when user clicks some link I want to show another page https://PageB.com which is hosted on another domain. With that I want to provide some additional information for Page B, which it can use during loading. It could be literally any data that Page A has: user name, address, theme, whatever else... Let's just assume that there's a lot of data that Page A can provide.

One of the solutions I know is to put this data into query parameters so navigation url would look something like: https://PageB.com?username=...&address=...&theme=... It's OK to use when number of parameters is fixed and "small", I mean when url length don't reach the limit. However if there's a lot of data it can't be used.

Another solution that I know is to temporarily store data on server: Page A makes POST request to the server, server stores data somewhere and returns a key that could be used to fetch that data. I navigate to Page B providing key in a query parameters - https://PageB.com?key={key}, and Page B should fetch data from the server using that key. This seem to be an OK solution for my example.

However I'd like to know if there is any other solution to this? What are the common practices when there's a lot of data to be provided?

Thanks in advance!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文