博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JS访问或设置cookie的方法+跨域调用方法
阅读量:7096 次
发布时间:2019-06-28

本文共 1089 字,大约阅读时间需要 3 分钟。

无意中从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);
}

转载于:https://www.cnblogs.com/qcxc/p/6857430.html

你可能感兴趣的文章
MHA切换过程:
查看>>
HanLP汉语言分析框架
查看>>
SQLite 日期操作
查看>>
热词分享
查看>>
phpcms相关
查看>>
thinkphp空控制器的处理
查看>>
Unity优化----drawcall系列
查看>>
通过按键实现LED灯的亮灭(含两种情况)
查看>>
C#中常用接口介绍
查看>>
swift 纯代码自定义控件
查看>>
使用Groovy的sql模块操作mysql进行多种查询
查看>>
解决mysql 主从数据库同步不一致的方法
查看>>
字符编码笔记:ASCII,Unicode 和 UTF-8
查看>>
Stack
查看>>
[BZOJ3631][JLOI2014]松鼠的新家(树链剖分)
查看>>
libgdx游戏引擎开发笔记(四)文字显示BitmapFont
查看>>
JavaScript和Webservice实现联动
查看>>
CSC
查看>>
pycharm 配置 anaconda ,以及anaconda的使用
查看>>
终端命令和环境变量
查看>>