当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 判断客户浏览器是否支持cookie

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 判断客户浏览器是否支持cookie


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 656 ::
收藏到网摘: n/a

判断客户浏览器是否支持cookie

    如果你的网页需要用cookie来保存之前访问你网页客户的信息,那首先你就必须确保你的客户端浏览器支持cookie,这包括浏览器的cookie选项是否启用(在大多数浏览器中都有这个选项),那么你既可以发出一条信息来提醒你的客户开启cookie,也可以创建代码来操纵这个选项,以使cookie选项启动。

        为了解决这个问题,用一下代码去检测你的客户端是否开启了cookie

<script type="text/javascript">
var cookieEnabled=(navigator.cookieEnabled)? true : false
//判断cookie是否开启
//如果浏览器不是ie4+或ns6+
if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){
document.cookie="testcookie"
cookieEnabled=(document.cookie=="testcookie")? true : false
document.cookie="" //erase dummy value
}
//if (cookieEnabled) 
//if cookies are enabled on client's browser
//do whatever
</script>