How to detect that JavaScript and/or Cookies are disabled?

前端 未结 9 1213
鱼传尺愫
鱼传尺愫 2020-11-27 14:13

How to detect that JavaScript or Cookies are disabled in the user\'s browser and notify him any help ?

9条回答
  •  囚心锁ツ
    2020-11-27 15:01

    // Example[1]: if ( hasCookies() )
    /**
    * @hasCookies:  Check if cookie's are Enabled
    * @param  {none} ''
    * @return {BOOLEAN} true|false
    */
    function hasCookies() {
    return (navigator.cookieEnabled);
    }
    
     // Example[2]: if ( JLS.TEST.COOKIE() )
    // Java Pattern ( How to write usable JS)
    /** @namespace JLS classes and functions. */
    var JLS = JLS || {};
    /**
    * TEST utility
    * @namespace JLS
    * @class TEST
    */
    JLS.TEST = {
    
    /**
    * @public-method COOKIE
    * @COOKIE  Check if cookie's are Enabled
    * @return {BOOLEAN} true|false
    */
     COOKIE: function () {
        //Change this (library). Not main.js (Algorithm)
        return (navigator.cookieEnabled);
        }
    };
    

提交回复
热议问题