Nokia 中的 WGZ 小部件不支持 cookie,但作为一种解决方法,我开始使用小部件,但好像它是一个 localStorage 对象;这是一个片段......我希望它有所帮助
干杯
if (!window.localStorage) {
if(typeof(widget)==='undefined')
{
//alert('working with an OS5 blackberry');
window.localStorage = {
getItem: function (sKey) {
if (!sKey || !this.hasOwnProperty(sKey)) { return null; }
return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
},
key: function (nKeyId) { return unescape(document.cookie.replace(/\s*\=(?:.(?!;))*$/, "").split(/\s*\=(?:[^;](?!;))*[^;]?;\s*/)[nKeyId]); },
setItem: function (sKey, sValue) {
if(!sKey) { return; }
document.cookie = escape(sKey) + "=" + escape(sValue) + "; path=/";
this.length = document.cookie.match(/\=/g).length;
},
length: 0,
removeItem: function (sKey) {
if (!sKey || !this.hasOwnProperty(sKey)) { return; }
var sExpDate = new Date();
sExpDate.setDate(sExpDate.getDate() - 1);
document.cookie = escape(sKey) + "=; expires=" + sExpDate.toGMTString() + "; path=/";
this.length--;
},
hasOwnProperty: function (sKey) { return (new RegExp("(?:^|;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie); }
};
window.localStorage.length = (document.cookie.match(/\=/g) || window.localStorage).length;
}
else
{
//alert('working with widgets');
window.localStorage={
getItem: function (sKey) {
return widget.preferenceForKey(sKey);
},
setItem: function (sKey, sValue) {
widget.setPreferenceForKey(sValue, sKey);
},
length: 0,
removeItem: function (sKey) {
widget.setPreferenceForKey(null,sKey );
},
hasOwnProperty: function (sKey) {
return widget.preferenceForKey(sKey)!==null;
}
};
}
}