如何检测JavaScript和/或Cookie被禁用? [英] How to detect that JavaScript and/or Cookies are disabled?

查看:363
本文介绍了如何检测JavaScript和/或Cookie被禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在用户的浏览器中检测到JavaScript或Cookies被禁用并通知他
任何帮助?

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

推荐答案

对于检查cookie,您可以使用:

For checking cookies you can use:

function checkCookie(){
    var cookieEnabled = navigator.cookieEnabled;
    if (!cookieEnabled){ 
        document.cookie = "testcookie";
        cookieEnabled = document.cookie.indexOf("testcookie")!=-1;
    }
    return cookieEnabled || showCookieFail();
}

function showCookieFail(){
  // do something here
}


// within a window load,dom ready or something like that place your:
checkCookie();

为了检查JavaScript,请使用< noscript>

And for checking JavaScript use a <noscript> tag with some kind of message inside

这篇关于如何检测JavaScript和/或Cookie被禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆