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.
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.
Whether or not javascript is enabled is only known from within the context of a browser, so the best you can do is write some browser-side code to set a flag based on if javascript is enabled or not. One possibility is do something like
and
This will redirect to an error page if script is disabled. Just replace
error.html
with the URL of your error page.Piece of cake!
Encompass your entire Javascript page in one DIV.
Overlay a second DIV of equal size that contains your non-Javascript page. Give that DIV an id and a high z-index:
In this second non-JS DIV, have your very first code be Javascript that sets this DIV's visibility to hidden:
No Javascript enabled? Nothing will happen and they'll see the overlying non-Javascript page.
Javascript enabled? The overlying non-Javascript page will be made invisible and they'll see the underlying Javascript page.
This also lets you keep the whole page in one file, making modifications easier, rather than trying to manage two files for the same page.
Yes. Make you have the latest jQuery.
Javascript:
PHP:
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
Use
<noscript>
tags to include a meta-redirect if the page does not have JavaScript.<noscript>
tags are called when the browser connecting to the page does not have JavaScript.