2012-07-27 49 views
-1

大家好,我正在开发一个使用phonegap的应用程序。我的应用程序在Android和黑莓手机上运行良好,但在symbian上无法正常工作。饼干不在symbian中工作

在我设置cookie喜欢的网页之一:

$.cookie("userName", userName, { path: '/' }); 
$.cookie("currentTime", currentTime, { path: '/' }); 

在另一页我尝试访问它想:

alert($.cookie('userName')); 

但警报显示“空”,但相同的代码在Android和黑莓上完美工作。
Symbian是否支持cookies?

回答

0

尝试另一种JS代码进行测试

// Function that create a cookie and set its value 
function setCookie(name, value, expiryDate) { 
document.cookie = escape(name) + "=" + escape(value) + "; path=/" + 
    ((expiryDate == null) ? "" : "; expires=" + expiryDate.toGMTString()); 
} 


// Function that gets the cookies value 
function getCookie(name) { 
var cookieName = name + "="; 
var documentCookie = document.cookie; 
var start, end; 

if(documentCookie.length > 0) { 
    start = documentCookie.indexOf(cookieName); 
    if(start != -1) { 
     start += cookieName.length; 
     end = documentCookie.indexOf(";", start); 
     if(end == -1) end = documentCookie.length; 

     return unescape(documentCookie.substring(start, end)); 
    } 
} 
return null; 
} 

您可以设置cookie与

setCookie('cookieName', value, cookieExpiry); 

而且随着诺基亚

getCookie('cookieName') 
0

WGZ部件得到其数值不支持cookies,但作为解决办法,我开始使用小部件,但好像它是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; 
} 
}; 
} 
}