Con*_*ton 5 javascript php mobile jquery ipad
我在尝试使用PHP或Javascript读取cookie时遇到了一些问题.我尝试过使用:
if(!$_COOKIE['popup_closed']
&& !isset($_COOKIE['username'])
&& !isset($_COOKIE['password'])
)
Run Code Online (Sandbox Code Playgroud)
我试过了:
if(
$.cookie('popup_closed') == null
&& $.cookie('username') == null
&& $.cookie('password') == null) {
doStuff();
}
Run Code Online (Sandbox Code Playgroud)
(使用jquery.cookie插件)
它们都不适用于iPad.它适用于所有浏览器,我试过谷歌搜索问题但似乎没有太多关于在iPad上阅读cookie的信息.
谢谢你们给予的任何帮助!
这实际上是一种解决方法,但如果它可用,你可以使用本地存储 - 至少我已成功地在iPad/iPhone中使用它.
例如,使用这种解决方案.
function saveData(name, value) {
if (typeof(localStorage) != 'undefined') {
localStorage.setItem(name, value);
} else {
createCookie(name, value, 7);
}
}
function loadData(name) {
var temp_value = '';
if (typeof(localStorage) != 'undefined') {
temp_value = localStorage.getItem(name);
} else {
temp_value = readCookie(name);
}
return temp_value;
}
function eraseData(name) {
if (typeof(localStorage) != 'undefined') {
localStorage.removeItem(name);
} else {
eraseCookie(name);
}
}
function createCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
else {
expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1,c.length);
}
if (c.indexOf(nameEQ) === 0) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2237 次 |
最近记录: |