zoukankan      html  css  js  c++  java
  • JavaScript操作cookie

    以下操作cookie在Firefox和Safari中测试成功,在IE中失败(读取、获取,改写,设置)。

    经过反复测试,发现把http://127.0.0.1改为http://localhost之后,IE中也可以正常运行。

    function getCookie(c_name) {
             if (document.cookie.length > 0) {
                 c_start = document.cookie.indexOf(c_name + "=");
                 if (c_start != -1) {
                     c_start = c_start + c_name.length + 1;
                     c_end = document.cookie.indexOf(";", c_start);
                     if (c_end == -1) c_end = document.cookie.length;
                     return (document.cookie.substring(c_start, c_end));
                 }
             }
             return ""
         }

         function setCookie(c_name, value, expiredays) {
             var exdate = new Date();
             exdate.setDate(exdate.getDate() + expiredays);
             document.cookie = c_name + "=" + value + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=/";
             ;
         }

         function checkCookie() {
             master_headertop_narrow_show = getCookie('master_headertop_narrow_show')
             alert(master_headertop_narrow_show); //////
             if (master_headertop_narrow_show != null && master_headertop_narrow_show != "") {
                 if (master_headertop_narrow_show == 'true') {
                     var master_headertop = document.getElementById('master_headertop');
                     if (master_headertop)
                         master_headertop.style.display = 'none';
                     var master_headertop_narrow = document.getElementById('master_headertop_narrow');
                     if (master_headertop_narrow)
                         master_headertop_narrow.style.display = 'block';

                 }
             }
         }

  • 相关阅读:
    SaltStack概述及安装
    Zabbix高可用
    Zabbix数据库表结构
    asp select count(*) 用 open还是excute
    asp+jquery+ajax,asp后台程序执行不正常
    aspupload ,在winows server 2008 下无法使用
    jquery 如何使用innerHTML
    thinkphp的select和find的区别(转)
    centos安装PHP-pdo支持pdo
    Excel 2007 打开 UTF-8 编码 CSV 文件的乱码BUG
  • 原文地址:https://www.cnblogs.com/emanlee/p/1786390.html
Copyright © 2011-2022 走看看