facebook

Cookies

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #325292 Reply

    hammet
    Member

    Hi,

    I have an app with a webview component where I load the html.

    I’m using cookies but when I close the app the cookies are deleted. Is this the normal behavior?

    Regards

    #325378 Reply

    hammet
    Member

    I use this code.

    It works while I don’t quit the app. When I close it the cookie doesn’t exist.

    /*!
    * jQuery Cookie Plugin
    * https://github.com/carhartl/jquery-cookie
    *
    * Copyright 2011, Klaus Hartl
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://www.opensource.org/licenses/mit-license.php
    * http://www.opensource.org/licenses/GPL-2.0
    */
    (function($) {
    $.cookie = function(key, value, options) {

    // key and at least value given, set cookie…
    if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
    options = $.extend({}, options);

    if (value === null || value === undefined) {
    options.expires = -1;
    }

    if (typeof options.expires === ‘number’) {
    var days = options.expires, t = options.expires = new Date();
    t.setDate(t.getDate() + days);
    }

    value = String(value);

    return (document.cookie = [
    encodeURIComponent(key), ‘=’, options.raw ? value : encodeURIComponent(value),
    options.expires ? ‘; expires=’ + options.expires.toUTCString() : ”, // use expires attribute, max-age is not supported by IE
    options.path ? ‘; path=’ + options.path : ”,
    options.domain ? ‘; domain=’ + options.domain : ”,
    options.secure ? ‘; secure’ : ”
    ].join(”));
    }

    // key and possibly options given, get cookie…
    options = value || {};
    var decode = options.raw ? function(s) { return s; } : decodeURIComponent;

    var pairs = document.cookie.split(‘; ‘);
    for (var i = 0, pair; pair = pairs[i] && pairs[i].split(‘=’); i++) {
    if (decode(pair[0]) === key) return decode(pair[1] || ”); // IE saves cookies with empty string as “c; “, e.g. without “=” as opposed to EOMB, thus pair[1] may be undefined
    }
    return null;
    };
    })(jQuery);

    function premiaPuntosPorEntrar() {
    var str_last_fecha_visitado=$.cookie(‘last_fecha_visitado’);

    myDate = new Date();
    if (str_last_fecha_visitado != myDate.toDateString()) {
    $.cookie(‘last_fecha_visitado’,myDate.toDateString());

    //alert(‘Has ganado 5 puntos por abrir hoy la aplicación!’);

    };
    }

    #325381 Reply

    support-michael
    Keymaster

    @hammet

    >I have an app with a webview component where I load the html.

    “webview component” implies you are building a native app with an embedded browser component such as an iOS UIWebView, right? If yes are you using a particular mobile SDK/framework, e.g., phonegap/cordova?

    UIWebView is an html render, and not as capable as a general browser. I just want to confirm before investigating this further?

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Cookies

You must be logged in to post in the forum log in