简体   繁体   English

如何使用Phonegap和jQuery Mobile在Android设备中存储cookie值?

[英]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: 就这么简单:

  • Setting a value: window.localStorage.setItem("sample", "value"); 设置值: window.localStorage.setItem("sample", "value");
  • Getting a 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.

相关问题 如何在Android中使用Phonegap处理Jquery mobile的设备后退按钮? - How to handle device back button for Jquery mobile using Phonegap in Android? 如何使用jQuery-mobile dreamviewer cc和android中的phonegap在sqlite数据库中存储数据? - How to store data in sqlite database using jQuery-mobile dreamviewer cc with phonegap in android? Phonegap + Jquery移动应用程序无法在Android设备上运行 - Phonegap + Jquery mobile app not working on android device 在使用Google Play商店的设备上安装JQuery Mobile应用程序和使用PhoneGap有什么区别 - What is the difference between installing JQuery Mobile application on a device using Google Play Store and using PhoneGap 如何使用android phonegap将公司名称存储到移动通讯录中? - How to store the company name to mobile contacts using android phonegap? 带有phonegap的jQuery-mobile在Android 4.0上未获取Cookie - Jquery-mobile with phonegap not getting cookies on Android 4.0 使用phonegap的Android cookie - Android cookies using phonegap 如何在Android Phonegap中使用jQuery Mobile创建工具栏? - How to create a tool bar using jquery mobile in android phonegap? 如何在PhoneGap Android中使用jQuery Mobile创建Swipeview - How to create Swipeview using jquery mobile in phonegap android Android中的PhoneGap + jQuery Mobile:如何使用HTML5调整标题 - PhoneGap + jQuery Mobile in Android: how to adjust the header using HTML5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM