이 코드를 사용할 수 있습니다. 쿠키 플러그인에 JQuery가 필요합니다. 임시 저장을위한 것이 아닙니다.
function GetData(key)
{
var sonuc = "";
if (typeof (localStorage)!="undefined")
{
//İkinci html5 localStorage desteği varmı ona bakılır
if (localStorage[key] != null)
{
sonuc= localStorage[key];
}
}
else
{
//son olarak cookie desteği varmı ona bakılır
sonuc=$.cookie(key);
}
return sonuc;
}
function SetData(key,value)
{
if (typeof (localStorage) != "undefined")
{
//ikinci önce html5 localStorage desteği varmı ona bakılır
try
{
localStorage.setItem(key, value);
return true;
} catch (e)
{
return false;
}
}
else
{
//son olarak cookie desteği varmı ona bakılır
try
{
$.cookie(key, value);
return true;
} catch (e)
{
return false;
}
}
}
/*this plugin is to add cookie function to jquery*/
/*Copyright (c) 2006 Klaus Hartl (stilbuero.de)*/
jQuery.cookie = function (name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
/*end of jquery plugin*/
지금까지 작성한 코드를 표시해야합니다.FYI, 그냥 AJAX 이상, 당신은 그냥 JS var에 데이터를 저장할 수 있습니다 ... – JAAulde
감사 JAAulde, 나는 아래에 대답을 accepeted하지만 귀하의 의견은 고마워 정확 :) – OriginalEXE