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

                 }
             }
         }

  • 相关阅读:
    设计模式外观模式
    SQL Server高级查询
    电脑双屏下如何设置程序在第二屏幕运行
    Vistual Studio自带的计划任务功能
    SQL Server定时创建动态表
    访问网站出现空白页面的原因和解决方法
    微软老将Philip Su的离职信:回首12年职场生涯的心得和随笔
    SQL Server更改字段名
    刷新本页与父页的两条代码
    色彩感情
  • 原文地址:https://www.cnblogs.com/emanlee/p/1786390.html
Copyright © 2011-2022 走看看