Check whether Javascript is enabled

后端 未结 9 2208
礼貌的吻别
礼貌的吻别 2020-12-29 13:47

Is there a way to check whether Javascript is enabled or supported by the browser? If it\'s not supported, I would like to redirect the user to a user-friendly error page. <

9条回答
  •  太阳男子
    2020-12-29 14:11

    As yet another option, you can (though it requires a second page visit) use javascript to set a cookie.

    If the cookie exists server-side (they have javascript) render the page as normal. During the absense of the cookie, you can either use a Location redirect, or render the appropriate [stripped-down] template to accommodate their lack of javascript support.

    page html

    
    

    page php

    if (isset($_COOKIE['hasJS'])){
      // normal page render
    }else{
      header('Location: http://mysite.com/index-nojs.php');
    }
    

提交回复
热议问题