How to set cookie for a dialog box in jquery? -


//----------jquery.cookie.js begins-------------  /*!   * jquery cookie plugin v1.4.1   * https://github.com/carhartl/jquery-cookie   *   * copyright 2006, 2014 klaus hartl   * released under mit license   */  (function (factory) {  	if (typeof define === 'function' && define.amd) {  		// amd (register anonymous module)  		define(['jquery'], factory);  	} else if (typeof exports === 'object') {  		// node/commonjs  		module.exports = factory(require('jquery'));  	} else {  		// browser globals  		factory(jquery);  	}  }(function ($) {    	var pluses = /\+/g;    	function encode(s) {  		return config.raw ? s : encodeuricomponent(s);  	}    	function decode(s) {  		return config.raw ? s : decodeuricomponent(s);  	}    	function stringifycookievalue(value) {  		return encode(config.json ? json.stringify(value) : string(value));  	}    	function parsecookievalue(s) {  		if (s.indexof('"') === 0) {  			// quoted cookie according rfc2068, unescape...  			s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');  		}    		try {  			// replace server-side written pluses spaces.  			// if can't decode cookie, ignore it, it's unusable.  			// if can't parse cookie, ignore it, it's unusable.  			s = decodeuricomponent(s.replace(pluses, ' '));  			return config.json ? json.parse(s) : s;  		} catch(e) {}  	}    	function read(s, converter) {  		var value = config.raw ? s : parsecookievalue(s);  		return $.isfunction(converter) ? converter(value) : value;  	}    	var config = $.cookie = function (key, value, options) {    		// write    		if (arguments.length > 1 && !$.isfunction(value)) {  			options = $.extend({}, config.defaults, options);    			if (typeof options.expires === 'number') {  				var days = options.expires, t = options.expires = new date();  				t.setmilliseconds(t.getmilliseconds() + days * 864e+5);  			}    			return (document.cookie = [  				encode(key), '=', stringifycookievalue(value),  				options.expires ? '; expires=' + options.expires.toutcstring() : '', // use expires attribute, max-age not supported ie  				options.path    ? '; path=' + options.path : '',  				options.domain  ? '; domain=' + options.domain : '',  				options.secure  ? '; secure' : ''  			].join(''));  		}    		// read    		var result = key ? undefined : {},  			// prevent loop in first place assign empty array  			// in case there no cookies @ all. prevents odd result when  			// calling $.cookie().  			cookies = document.cookie ? document.cookie.split('; ') : [],  			i = 0,  			l = cookies.length;    		for (; < l; i++) {  			var parts = cookies[i].split('='),  				name = decode(parts.shift()),  				cookie = parts.join('=');    			if (key === name) {  				// if second argument (value) function it's converter...  				result = read(cookie, value);  				break;  			}    			// prevent storing cookie couldn't decode.  			if (!key && (cookie = read(cookie)) !== undefined) {  				result[name] = cookie;  			}  		}    		return result;  	};    	config.defaults = {};    	$.removecookie = function (key, options) {  		// must not alter options, extending fresh object...  		$.cookie(key, '', $.extend({}, options, { expires: -1 }));  		return !$.cookie(key);  	};    }));  //---------------jquery.cookie.js ends-----------  var $j = jquery.noconflict();     $j(document).ready(function()  {  		  		$.cookie('the_cookie', 'the_value');  		var mycookie = $.cookie('the_cookie');  		alert(mycookie);  		  		$j('#popup_content').dialog  		(  		{  			modal:true,  			resizable:false,  			draggable:false,  			height: 525,  			width:475,   			closeonescape: true,  		}  		);    });    	function setcookie(cname, cvalue, exdays)   	{  		var d = new date();  		d.settime(d.gettime() + (exdays*24*60*60*1000));  		var expires = "expires="+d.toutcstring();  		document.cookie = cname + "=" + cvalue + "; " + expires;  	}

i want dialog box open once , read can done adding cookies dialog box. on searching, got code add cookies dialog box not working. don't know error is. new jquery. want dialog box should open once.

this entire code of jquery.cookie.js.

thanks in advance. :)

please check whether getting below error in console,

typeerror: $.cookie not function

if please include jquery library cookie functions..

please see below link more info,

$.cookie not function typeerror

try below code, include jquery dialog box related library,

<head>  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"> </script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"> </script>               <script type="text/javascript">  		  $(function() {  		    		  $.cookie('showdialog', true);   		  alert($.cookie('showdialog'));  		    	if ($.cookie('showdialog') == undefined || $.cookie('showdialog') == null || $.cookie('showdialog') != 'false')   		{    			$('#popup_content').dialog  			(  			{  				modal:true,  				resizable:false,  				draggable:false,  				height: 525,  				width:475,   				closeonescape: true,  			}  			);  			$.cookie('showdialog', 'false', { expires: 1 }); // set cookie, expiry after 1 day  		}  		  		  		    	});  		     		   </script>  </head>


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -