zoukankan      html  css  js  c++  java
  • js存/讀取cookie函數

    /*---------------------------Cookie操作---------
    *cookieName   cookie名稱
    *cookieValue   cookie值
    *seconds        設置過期時間,單位秒
    *path             存放路徑
    *domain         定義域
    *secure          默认情况下cookie在网路上传输采用的是普遍的、不加密的http传输,但这种方式不安全,容易被窃听。在JavaScript中,可以设置cookie的secure,那么cookie就只能通过https或其他安全协议才能传输。cookie的secure是一个布尔类型的值,secure值为true时,在http中是无效的,在https中才有效。
    */

    /*設置cookie*/
    function setCookie(cookieName, cookieValue, seconds, path, domain, secure){
        var expires  = new Date();
        if(cookieValue == '' || seconds < 0) {
            cookieValue = '';
            seconds = -2592000;
        }
        expires.setTime(expires.getTime() + seconds * 1000);
        domain = !domain ? '' : domain;
        path = !path ? '' : path;
        document.cookie = escape(cookieName) + "="+ escape (cookieValue)
        + ( expires ? ";expires = " + expires.toGMTString() : '' )
        + ( path ? ";path = "+path : '/')
        + ( domain ? ";domain = "+domain : '')
        + ( secure ? ";secure" : '' );
    };
    //取cookies函数 
    function getCookie(cookieName){      
        var arr = document.cookie.match(new RegExp("(^| )"+cookieName+"=([^;]*)(;|$)"));
        if(arr != null) return unescape(arr[2]); return null;
    };
  • 相关阅读:
    flutter 右滑返回上一页
    flutter 的Animation简单了解
    Flutter Offstage、Visibility隐藏/可见
    flutter手势
    Flutter生命周期
    flutter 路由动画
    flutter 保持页面状态
    flutter 不规则底部工具栏实现
    flutter 主页面底部导航栏实现以及主题风格设置
    flutter DropdownButton使用
  • 原文地址:https://www.cnblogs.com/helin/p/3030059.html
Copyright © 2011-2022 走看看