Is an external javascript file loading between HTML pages?

I am working on a basic HTML / CSS / JavaScript quiz website.

I use external JavaScript to collect data from an HTML form in JavaScript as such:

var userInfo = [];
function savePerson(form)
{
    userInfo[0] = form.store.value;
    userInfo[1] = form.employeeId.value;
    userInfo[2] = form.fName.value;
    userInfo[3] = form.lName.value;
};

This works great.

Now I need to go to another HTML page, but save it in an array. Does JavaScript reload between HTML files? If so, how do you save the values ​​from the script across multiple pages?

+4
source share
4 answers

You must either store them on the client side or on the server side.

For server storage, you need to send data to the server through ajax and save it in any database.

cookie, localstorage, indexeddb, websql.

:

localStorage.setItem('myPerson', JSON.stringify(userInfo));
0

.js , html5. html js script.

0

If you use confidential information, you probably want to use a background service to store and retrieve such data, but local storage or cookies can be used in most cases.

Here is an example of using local storage

Set the item:

localStorage.setItem('userInfo', userInfo);

then on the next page use this to get the item:

var userInfo = localStorage.getItem("userInfo");
0
source

use localstorage

//save datas:
localStorage.setItem('data', JSON.stringify(info));


//get datas:
var data=localStorage.getItem('data');
0
source

Source: https://habr.com/ru/post/1669956/


All Articles