将数据从一个网页传递到另一个网页 [英] Passing data from one web page to another

查看:102
本文介绍了将数据从一个网页传递到另一个网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用客户端技术将潜在的大量数据从一个页面传递到另一个页面。它基本上是一个id列表,它将显示在目标页面上。显然查询字符串不合适,因为可能有数千个ID,所以我认为我可以使用javascript动态添加表单(method = GET),将id写入隐藏字段并将表单提交到目标页面。它似乎工作正常,但我想知道是否有更好的方法 - 这感觉有点hacky。

I need to pass a potentially large amount of data from one page to another using client side techniques. It is basically a list of id's which will get displayed on the target page. Obviously query string is not suitable as there could be thousands of ids so I thought I could use javascript to dynamically add a form (method=GET), write the ids into a hidden field and submit the form to the target page. It seems to work ok but I want to know if there is a better way of doing it - this feels a bit hacky.

推荐答案

通过使用 html5 storage api ,您可以实现这一目标...

By using html5 storage api you can achieve this...

使用 HTML5 ,网页可以在用户的​​浏览器中本地存储数据。

With HTML5, web pages can store data locally within the user's browser.

之前,这是通过cookie完成的。但是,Web存储更安全,更快捷。每个服务器请求都不包含这些数据,但仅在被要求时使用。也可以存储大量数据,而不会影响网站的性能。

Earlier, this was done with cookies. However, Web Storage is more secure and faster. The data is not included with every server request, but used ONLY when asked for. It is also possible to store large amounts of data, without affecting the website's performance.

数据存储在键/值对中,网页只能访问数据自行存储。

The data is stored in key/value pairs, and a web page can only access data stored by itself.


  • localStorage - 存储没有过期日期的数据

  • sessionStorage - 存储一个会话的数据

  • localStorage - stores data with no expiration date
  • sessionStorage - stores data for one session

示例:

设置

window.localStorage.setItem("name",document.getElementById("name").value);

获取

var name = window.localStorage.getItem("name");

有关详细信息,请参阅 HTML5存储

For more reference see HTML5 storage

注意: Internet Explorer 8+支持网络存储,Firefox,Opera,Chrome和Safari

这篇关于将数据从一个网页传递到另一个网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆