js判断浏览器Cookie功能是否开启兼容IE,firefox,chrome,opera
js判断浏览器Cookie功能是否开启兼容IE,firefox,chrome,operajsvascript代码如下:<script type="text/javascript">
function CookieEnable()
{
var result=false;
if(navigator.cookiesEnabled)
return true;
document.cookie = "testcookie=yes;";
var cookieSet = document.cookie;
if (cookieSet.indexOf("testcookie=yes") > -1)
result=true;
document.cookie = "";
return result;
}
if(!CookieEnable())
{
alert("对不起,您的浏览器的Cookie功能被禁用,请开启");
}
</script>说明: 上面的js代码主要是 写一个cookie到客户端然后马上再来读取这个cookie,如果读取到的cookie为空,
则表示客户端禁止了cookie,那我们就不要再用cookie来储存用户信息了
兼容IE,firefox,chrome,opera的COOKIE检测试代码为:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>您的浏览器禁止了脚本运行</title>
<script language="javascript" type="text/javascript">
window.onload=function()
{
document.getElementById('jscheck').style.display='none';
document.getElementById('normalcontent').style.display='';
if(!(document.cookie || navigator.cookieEnabled))
{
alert('cookie 未打开!');
}
};
</script>
</head>
<body>
<div id="jscheck">您的浏览器禁止了脚本运行,本系统无法启动!</div>
<div id="normalcontent" style="display:none;">这里是正文</div>
</body>
</html>js判断浏览器Cookie功能是否开启兼容IE,firefox,chrome,opera
参考:
http://blog.sina.com.cn/s/blog_6436b8ec0100y7up.html
http://www.cnblogs.com/Ren_Lei/archive/2010/09/30/1839399.html
页:
[1]