Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing data from one web page to another

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.

like image 963
HammerIp Avatar asked Nov 22 '12 09:11

HammerIp


People also ask

How do I transfer data from one HTML page to another?

Simpler way to do it is by adding it to the link which is fine when you have static values. But in case of variables your only option is JavaScript. And then all you have to do on the second page is just read the values from the URL params.

What are the two methods of passing data between pages?

Passing variables between pages using URL GET or POST method.


2 Answers

By using HTML5 Storage API you can achieve this...

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

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 - stores data with no expiration date
  • sessionStorage - stores data for one session

Example:

To set

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

To get

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

For more reference see HTML5 storage

Note: Web storage is supported in Internet Explorer 8+, Firefox, Opera, Chrome, and Safari.

like image 109
Talha Avatar answered Sep 29 '22 17:09

Talha


Thusends of IDs isn't so much. If the IDs are GUIDs there will be Nx32 bytes. You could use jQuery post, which will trigger a HTTP Post.

like image 38
Simon Edström Avatar answered Sep 29 '22 16:09

Simon Edström