[英]Replacement for window.sessionStorage in Javascript?
我有一個帶有啟動頁面的應用程序,該應用程序需要確定已打開的內容,因此它不會在另一個新選項卡中重新打開已打開的內容。 在Firefox中,通過使用window.sessionStorage存儲打開的頁面的標題,然后使用帶有以下代碼的window.opener從列表中刪除標題,我能夠做到這一點。
if (window.sessionStorage) {
if (window.sessionStorage.getItem(code)) {
return; // page already open
}
else {
window.sessionStorage.setItem(code, code);
window.open("Sheet.aspx", "_blank");
}
}
在打開的頁面上:
function signalPageExit() {
if (window.opener.sessionStorage) {
window.opener.sessionStorage.removeItem(
document.getElementById("runcode").childNodes[0].textContent);
}
這在IE中不起作用,因此我決定使用cookie策略,但是cookie從未成功從動態啟動頁面上的代碼中刪除,因此一旦啟動頁面,就無法從啟動頁面重新打開頁面,直到Cookie已過期。
我的第二個嘗試是定義不存在的sessionStorage。 看起來像這樣:
function setStoreItem(name, val) {
this.storage[name] = val;
}
function getStoreItem(name) {
return(this.storage[name]);
}
function removeStoreItem(name) {
this.storage[name] = null;
}
function sesStorage() {
this.storage = new storageData();
this.setItem = setStoreItem;
this.getItem = getStoreItem;
this.removeItem = removeStoreItem;
}
// storage object type declaration
function storageData() {
}
// IE 7 and others
else {
window.sessionStorage = new sesStorage();
window.sessionStorage.setItem(code, code);
window.open("Sheet.aspx", "_blank");
}
但是似乎真正的會話存儲是特殊的,窗口的這個普通對象在回發之間並沒有保持活動狀態,因此,當我的啟動頁面回發時,創建的頁面標題列表就被清除了。
所以現在我正在尋找一種使這項工作可行的方法。 我有一個名為scoresheets.aspx的啟動頁面,該頁面根據用戶請求創建動態頁面。 這些頁面共享大量的javascript代碼,可以對其進行修改以使其正常工作。
當用戶嘗試重新打開啟動的頁面時,我不想刷新啟動的頁面,但是如果有某種方法可以檢測打開的頁面的標題,或者通過其他方式使用window.opener與sessionStorage具有相同的持久性進行通信,我很高興使用它。
您應該使用該Cookie策略,並將這些Cookie設置為在關閉窗口(標簽)時過期。 應該可以跨瀏覽器運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.