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);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM