在另一个页面中设置JavaScript变量



我目前正在学习JavaScript和PHP,遇到了一个简单的问题。我有一个脚本文件,它收集一些特定的数据,我可以将其保存到一个变量中。我正在努力打开另一个页面(.PHP(,并将收集到的数据设置为该页面中的textarea标记。因此,为了重述,我点击发送,脚本收集数据,打开第二个页面,并将其放入我为其创建的textarea

document.getElementById('getJSON').addEventListener('click', function() {
var survey_schema =formBuilder.actions.getData('json'); //the variable i want to send
alert (survey_schema); // just test alert to check data
//some code should be here (any help ??)
});

任何帮助都将不胜感激。提前感谢

您可以在浏览器的一种共享内存中使用localStorage

localStorage和sessionStorage属性允许保存密钥/值在web浏览器中配对。

var yourObj = { 'one': 1, 'two': 2, 'three': 3 };
// Put the object into storage in first page with a custom key
localStorage.setItem('KeyObject', JSON.stringify(yourObj));
// Retrieve the object from storage in other page based on key
// Note that also you can send key as queryString
var retrievedObject = localStorage.getItem('KeyObject');
//convert to josn
var json = JSON.parse(retrievedObject)
console.log(json);

最新更新