[英]How to store cookies values in an Android device using Phonegap and jQuery Mobile?
I am developing an app using jQuery1.6.1, Phonegap 1.5(cordova-1.5.0.js), jQuery Mobile 1.0.1, and the cookies plugin (jquery.cookies.2.2.0.js) in Android. 我正在使用Android中的jQuery1.6.1,Phonegap 1.5(cordova-1.5.0.js),jQuery Mobile 1.0.1和cookie插件(jquery.cookies.2.2.0.js)开发一个应用程序。
I want to set cookies in one page and want to access the same cookies in another page. 我想在一个页面中设置cookie,并想在另一页面中访问相同的cookie。
To Set 设置
$.cookies.set('sample', 'Cookies_Value');
To Get 要得到
$.cookies.get('sample');
While accessing the app on device, I am unable to set and get the cookies values. 访问设备上的应用程序时,无法设置和获取cookie值。 Is there any other way to store the cookies in device?
还有其他方法可以将Cookie存储在设备中吗?
It's not reliable to use cookies with PhoneGap/Cordova on Android, so I suggest using localStorage instead. 将Cookie与Android上的PhoneGap / Cordova一起使用并不可靠,因此我建议改为使用localStorage 。
It's as easy as this: 就这么简单:
window.localStorage.setItem("sample", "value");
window.localStorage.setItem("sample", "value");
window.localStorage.getItem("sample");
window.localStorage.getItem("sample");
I don't think Phonegap provides the functionality to store cookies. 我认为Phonegap不提供存储cookie的功能。
As you are already using JQuery. 由于您已经在使用JQuery。 You can look at below Plugin.
您可以在下面查看插件。
https://github.com/carhartl/jquery-cookie https://github.com/carhartl/jquery-cookie
Hope this help. 希望能有所帮助。
I have tested the same apps in different emulator versions. 我已经在不同的模拟器版本中测试了相同的应用程序。
I am able to store the cookies in Android 2.2. 我可以在Android 2.2中存储Cookie。 But its not working on Android 4.0.3.
但它不适用于Android 4.0.3。
As per my understand, Latest android version(Android 4.0.3) is not supporting. 据我了解,最新的android版本(Android 4.0.3)不支持。
In your first html page after logging in (I presume you have to login)..... using javascript write document.cookie=""; 登录后在您的第一个html页面中(我想您必须登录).....使用javascript写document.cookie =“”; .. it will be passed along each webpage that will be called later..
..它将沿着每个网页传递,稍后将被调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.