zoukankan      html  css  js  c++  java
  • JS访问或设置cookie的方法+跨域调用方法

    无意中从163网站获取的JS访问或设置cookie的方法,Log到日志上以防遗忘

    //COOKIE功能检查
    function fCheckCookie(){
        if(!navigator.cookieEnabled){
            alert("您好,您的浏览器设置禁止使用cookie\n请设置您的浏览器,启用cookie功能,再重新登录。");
        }
    }

    //获取Cookie
    function fGetCookie(sName){
       var sSearch = sName + "=";
       if(document.cookie.length > 0){
          offset = document.cookie.indexOf(sSearch)
          if(offset != -1){
             offset += sSearch.length;
             end = document.cookie.indexOf(";", offset)
             if(end == -1) end = document.cookie.length;
             return unescape(document.cookie.substring(offset, end))
          }
          else return ""
       }
    }

    //设置Cookie
    function fSetCookie(name, value, isForever, domain){
        var sDomain = ";domain=" + (domain || gOption["sCookieDomain"] );
        document.cookie = name + "=" + escape(value) + sDomain + (isForever?";expires="+  (new Date(2099,12,31)).toGMTString():"");
    }

    /跨域调用方法
    function fGetScript(sUrl){
        var oScript = document.createElement("script");
        oScript.setAttribute("type", "text/javascript");
        oScript.setAttribute("src", sUrl);
        try{oScript.setAttribute("defer", "defer");}catch(e){}
        window.document.body.appendChild(oScript);
    }

  • 相关阅读:
    bzoj1042: [HAOI2008]硬币购物(DP+容斥)
    bzoj3680: 吊打XXX(模拟退火)
    bzoj1867: [Noi1999]钉子和小球(DP)
    iOS怎样获取任何App的资源图片?
    iOS常用第三方库
    iOS应用上架报错解决
    iOS视频直播用到的协议
    iOS开发常用第三方框架
    iOS 打包Framework包含其他Framework的问题
    http和https的区别
  • 原文地址:https://www.cnblogs.com/dwfbenben/p/2543327.html
Copyright © 2011-2022 走看看