2012-07-27 48 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; 
} 
}; 
} 
}