How does a page get the value of a variable in a js file modified by another page?

1. There is a data.js file that defines only one variable var project= {}
2.a.html reference data.js < script src= ".. / js/data.js" > < / script >. There is a function in a.html that gets the return value from the server and assigns it to the variable project

in data.js.
       browse:function (pro) {
            project=pro;//a.htmlporjectdata.jsproject
            console.log(pro);
            console.log(project);
            window.open("test.html");
        },
     

console print, pro,project, has value and is equal.
3.test.html also refers to data.js < script src= ".. / js/data.js" > < / script >, but jumping to test.html,test.html print project is empty in a.html. How to solve this problem?

clipboard.png

Mar.02,2021

//  pro
// a.html
window.localStorage.setItem('data',JSON.stringify(pro))

// test.html
var data = JSON.parse(window.localStorage.getItem('data'))

as for your question @ luozz the example has been given in great detail


use localstronge to solve


there are at least three ways
1. Save cookie
2. Deposit localStorage
3. Save it in the server session before fetching


from it.

on the face of it, it is as if I added the goods to the shopping cart in JD.com, and then opened Taobao, and found that it was the same reason why there were no items in the shopping cart. How can two completely independent pages share data in this way?

I see vue in the title tag. You can use components to pass values , vuex , Bus (new Vue) , etc., or to share data locally. Choose cookie , sessionStroage or localStroage according to your needs. There are many ways!
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3164d-2bda8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3164d-2bda8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?