Suppose you wanted to pass two pieces of information: var param1 = "foo"
and var param2 = "bar"
from page1.html
to page2.html
This is called "persisting data between requests" and can be done in a variety of ways:
Specify parameters in url:
myurl.com/page2.html?param1=foo¶m2=bar
a. This can be done by clicking a link like above b. Or by submitting a form withaction="myurl.com/page2.html"
and with fields named "param1" and "param2" and values "foo" and "bar" c. Or by settingwindow.location.href = "myurl.com/page2.html?param1=value1¶m2=value2"
in JavaScript.To retrieve the parameters from url in page2.html you'd either get them in your PHP or ASP or JSP scripts or by parsing the url with javascript.
Set
localStorage.param1 = "foo"; localStorage.param2 = "bar"
, and getting them same way on page2.html with javascript:var param1 = localStorage.param1
. This assumes page1 and page2 are both under the same host: "myurl.com" or whatever.Set your data in cookie on page1.html and get it from cookies in page2.html. This also assumes the pages are hosted under the same host name.
Once you've mastered server side scripting, like PHP you can use Ajax to store data on server between page requests.
Alternatively, you can store data with 3rd party using their API with JavaScript, but this is rarely necessary and is advanced topic.
Hope that helps.