Ver Mensaje Individual
  #3 (permalink)  
Antiguo 31/07/2014, 12:46
Jhon Silver
 
Fecha de Ingreso: marzo-2004
Ubicación: Madrid (España)
Mensajes: 837
Antigüedad: 20 años, 1 mes
Puntos: 9
Respuesta: Crear aviso de utilización de cookies

Al final he optado por el plugin de jQuery Cookies
El caso es que me aparece el mensaje correctamente pero en la pestaña de cerrar esta no se cierra, se mantiene abierta. Os paso el código del .js por si me podeis echar una mano:
Código Javascript:
Ver original
  1. document.write("<style>.msgcookie{display:block;position:fixed;bottom:0;height:50px;width:100%;background:rgba(0,0,0,0.8);color:#fff;font-size:11px;font-family:sans-serif}.msgcookie p{width:960px;margin:0 auto;background:url(http://www.web.com/src/images/cookie.png) 0 0 no-repeat;padding:10px 0 0 30px}.msgcookie p a:link,.msgcookie p a:active,.msgcookie p a:visited,.msgcookie p a:hover{color:#fff}.msgcookie a.close{float:right;display:block;width:16px;height:50px;background:url(http://www.web.com/src/images/cookie.png) 0 -45px no-repeat;overflow:hidden;text-indent:-80px;opacity:0.5;margin:0 0 0 40px}a.close:hover{opacity:1}</style>");
  2.  
  3.  
  4.  
  5. /*!
  6.  * jQuery Cookie Plugin v1.4.0
  7.  * https://github.com/carhartl/jquery-cookie
  8.  *
  9.  * Copyright 2013 Klaus Hartl
  10.  * Released under the MIT license
  11.  */
  12. (function (factory) {
  13.     if (typeof define === 'function' && define.amd) {
  14.         // AMD. Register as anonymous module.
  15.         define(['jquery'], factory);
  16.     } else {
  17.         // Browser globals.
  18.         factory(jQuery);
  19.     }
  20. }(function ($) {
  21.  
  22.     var pluses = /\+/g;
  23.  
  24.     function encode(s) {
  25.         return config.raw ? s : encodeURIComponent(s);
  26.     }
  27.  
  28.     function decode(s) {
  29.         return config.raw ? s : decodeURIComponent(s);
  30.     }
  31.  
  32.     function stringifyCookieValue(value) {
  33.         return encode(config.json ? JSON.stringify(value) : String(value));
  34.     }
  35.  
  36.     function parseCookieValue(s) {
  37.         if (s.indexOf('"') === 0) {
  38.             // This is a quoted cookie as according to RFC2068, unescape...
  39.             s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
  40.         }
  41.  
  42.         try {
  43.             // Replace server-side written pluses with spaces.
  44.             // If we can't decode the cookie, ignore it, it's unusable.
  45.             // If we can't parse the cookie, ignore it, it's unusable.
  46.             s = decodeURIComponent(s.replace(pluses, ' '));
  47.             return config.json ? JSON.parse(s) : s;
  48.         } catch(e) {}
  49.     }
  50.  
  51.     function read(s, converter) {
  52.         var value = config.raw ? s : parseCookieValue(s);
  53.         return $.isFunction(converter) ? converter(value) : value;
  54.     }
  55.  
  56.     var config = $.cookie = function (key, value, options) {
  57.  
  58.         // Write
  59.         if (value !== undefined && !$.isFunction(value)) {
  60.             options = $.extend({}, config.defaults, options);
  61.  
  62.             if (typeof options.expires === 'number') {
  63.                 var days = options.expires, t = options.expires = new Date();
  64.                 t.setDate(t.getDate() + days);
  65.             }
  66.  
  67.             return (document.cookie = [
  68.                 encode(key), '=', stringifyCookieValue(value),
  69.                 options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
  70.                 options.path    ? '; path=' + options.path : '',
  71.                 options.domain  ? '; domain=' + options.domain : '',
  72.                 options.secure  ? '; secure' : ''
  73.             ].join(''));
  74.         }
  75.  
  76.         // Read
  77.  
  78.         var result = key ? undefined : {};
  79.  
  80.         // To prevent the for loop in the first place assign an empty array
  81.         // in case there are no cookies at all. Also prevents odd result when
  82.         // calling $.cookie().
  83.         var cookies = document.cookie ? document.cookie.split('; ') : [];
  84.  
  85.         for (var i = 0, l = cookies.length; i < l; i++) {
  86.             var parts = cookies[i].split('=');
  87.             var name = decode(parts.shift());
  88.             var cookie = parts.join('=');
  89.  
  90.             if (key && key === name) {
  91.                 // If second argument (value) is a function it's a converter...
  92.                 result = read(cookie, value);
  93.                 break;
  94.             }
  95.  
  96.             // Prevent storing a cookie that we couldn't decode.
  97.             if (!key && (cookie = read(cookie)) !== undefined) {
  98.                 result[name] = cookie;
  99.             }
  100.         }
  101.  
  102.         return result;
  103.     };
  104.  
  105.     config.defaults = {};
  106.  
  107.     $.removeCookie = function (key, options) {
  108.         if ($.cookie(key) === undefined) {
  109.             return false;
  110.         }
  111.  
  112.         // Must not alter options, thus extending a fresh object...
  113.         $.cookie(key, '', $.extend({}, options, { expires: -1 }));
  114.         return !$.cookie(key);
  115.     };
  116.  
  117. }));
  118.  
  119.  
  120.  
  121.  
  122. $(document).ready(function()
  123. {
  124.     if (!$.cookie("msgcookie"))
  125.     {
  126.         $("body").prepend("<div class='msgcookie'><p><a href='#' class='close'>cerrar mensaje</a>Esta web utiliza 'cookies' propias y de terceros para ofrecerle una mejor experiencia y servicio y poder registrar el proceso de compra. Al navegar o utilizar nuestros servicios el usuario acepta el uso que hacemos de las 'cookies'. <a href='http://www.miweb.com/cookies'>M&aacute;s informaci&oacute;n</a></p></div>");
  127.        
  128.         $("body").on("click", ".close", function(e) {
  129.             e.preventDefault();
  130.             $.cookie('msgcookie', 'aceptado');
  131.             $(".msgcookie").fadeOut();
  132.         });
  133.     }
  134. });
en la linea 126 donde aparece la almohadilla se debería cerrar el mensaje pero esto no ocurre