I have defined a json object as
function getPost()
{
var fname = document.getElementById("fname").value;
var lname = document.getElementById("lname").value;
var v = {
"name": {
"firstname": fname,
"lastname": lname
}
};
}
How can I make this JSON variable v accessible to other pages. I want to pass the JSON data across pages.
You can store data locally within the user's browser using localStorage or SessionStorage( more information ) to access your data in all pages.
Take a look at this example:
localStorage.setItem('a', '{ "name" : "test"}');
eval("var myObj = " + localStorage.getItem('a'));
myObj.name; // test
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.