我正在开发一个NW.js(Node-Webkit)应用程序,我注意到我正在使用的本地存储对象没有持久化。
问题很简单我想,数据会保存在本地存储对象中,然后当打开window.open
窗口时,它应该打印保存的数据,但是当我打开开发工具时,我只注意到该名称。存在“view”的本地存储对象,但该值为空(undefined
)。令人恼火的是它在浏览器(chrome,firefox等)中运行良好。
这是我的代码
var count = 3600,
counter,
seconds,
minutes,
startGameBtn = document.getElementById('start-game-btn'),
slaveScreen = document.getElementById('slave-screen');
//When this button is pressed a count down starts from 1 hour
startGameBtn.addEventListener('click', function() {
counter = setInterval(timer, 1000);
GameplayStatus = true;
if (GameplayStatus) {
this.disabled = true;
}
function timer() {
count = count - 1;
if (count == -1) {
clearInterval(counter);
return;
}
seconds = count % 60;
minutes = Math.floor(count / 60);
minutes %= 60;
masterScreen.innerHTML = minutes + ":" + seconds;
localStorage.setItem('view', minutes + ":" + seconds);
}
});
//In order to recognize the new window and be able to target it
if (location.hash) {
setInterval(function() {
//should print the timer in the new window constantly. Works perfectly on the browser but doesn't display anything on node-webkit. The key exists but the value is empty (undefined)
slaveScreen.innerHTML = localStorage.getItem('view');
}, 50);