質問

How to pass the information from "myfirstpage.com" to "mysecondpage.com" ? I got my site on myfirstpage, but I'm changing the host and switching address to mysecondpage, I want an easy way to move over all users information they have stored in JavaScript local storage to my second page.

The best would be if you press an button, you'll directly go to my second page and all information would be stored in that page localstorage.

Security for storing and transfer the information is not important because it does not matter.

I'm have just learned HTML, css and JS. I have not learned Php yet but feel free to answer with php if that is the easiest way to do this.

役に立ちましたか?

解決

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:

  1. Specify parameters in url: myurl.com/page2.html?param1=foo&param2=bar a. This can be done by clicking a link like above b. Or by submitting a form with action="myurl.com/page2.html" and with fields named "param1" and "param2" and values "foo" and "bar" c. Or by setting window.location.href = "myurl.com/page2.html?param1=value1&param2=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.

    Read about passing params in url

  2. 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.

    Read about localStorage and sessionStorage

  3. 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.

    Read about cookies

  4. Once you've mastered server side scripting, like PHP you can use Ajax to store data on server between page requests.

    Read about Ajax

  5. Alternatively, you can store data with 3rd party using their API with JavaScript, but this is rarely necessary and is advanced topic.

    Cloud database services

    Hope that helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top