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';

                 }
             }
         }

  • 相关阅读:
    最小公倍数
    记录输入的数字并输出
    带时间的进度条
    进度条二:普通版
    文件的练习
    《k8s权威指南》读书笔记
    面试后如何判断岗位是否符合自己要求
    索引的三星系统
    使用Mysql分区表对数据库进行优化
    MySQL索引的基本操作
  • 原文地址:https://www.cnblogs.com/emanlee/p/1786390.html
Copyright © 2011-2022 走看看