当用户离开浏览器并将其存储在本地存储中时,我试图获取div的位置,当我刷新页面时它工作正常,但是当我关闭浏览器或选项卡时,它会将位置存储为零! ,我无法弄明白,下面是我正在使用的代码,欣赏一下,
编辑:刚刚尝试过,如果我关闭整个浏览器似乎它正在工作,但是当只关闭选项卡时它会给出零,任何想法?window.onunload = window.onbeforeunload = function () {
for (var i = 0; i < localStorage.length; i++) {
var localVariable = localStorage.key(i);
if (localVariable.substring(0, 3) == 'box') {
var label = JSON.parse(localStorage.getItem(localVariable)).label;
var boxRealId = JSON.parse(localStorage.getItem(localVariable)).boxId;
var positionTop = $('#flowchartWindow' + boxRealId).position().top;
var positionLeft = $('#flowchartWindow' + boxRealId).position().left;
var positionAppId = JSON.parse(localStorage.getItem(localVariable)).appId;
localStorage.removeItem(localVariable);
localStorage.setItem('box-app ' + positionAppId + '-box' + boxRealId, JSON.stringify({
appId: positionAppId,
boxId: boxRealId,
label: label,
positionTop: positionTop,
positionLeft: positionLeft,
}));
}
}