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.
I am using jQuery and the PHP Zend Framework.
Click the wrench icon on the toolbar. Click Options > Under the Hood. In the Privacy section, click Content settings. Scroll to the JavaScript section and click Allow all sites to run JavaScript (recommended).
Verify that JavaScript is disabled. First, click on the "Security" tab. Under the "Web content" section, you'll see a box next to "Enable JavaScript." If the box is unchecked, that means JavaScript has been disabled.
On Google Chrome, JavaScript is enabled by default, but you can verify if it works through the Settings menu. To reveal the Settings menu, simply click on three tiny black dots at the top-right corner of your Chrome window.
<noscript><meta http-equiv="refresh" content="1;url=error.html"></noscript>
This will redirect to an error page if script is disabled. Just replace error.html
with the URL of your error page.
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
<script type="text/javascript">
document.cookie = 'hasJS=true';
</script>
page php
if (isset($_COOKIE['hasJS'])){
// normal page render
}else{
header('Location: http://mysite.com/index-nojs.php');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With