chaseman Posted May 1, 2011 Share Posted May 1, 2011 I'd like to do a check if JavaScript is disabled in the user's browser, and based on that I'd like to do a if statement. How can I do that? I appreciate any suggestions. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/235280-how-to-check-if-javascript-is-diabled/ Share on other sites More sharing options...
fugix Posted May 1, 2011 Share Posted May 1, 2011 I would say that the best method is to use JavaScript to drop a cookie, and then test for that cookie in your server side scripting for future page views, and deliver content appropriately. Quote Link to comment https://forums.phpfreaks.com/topic/235280-how-to-check-if-javascript-is-diabled/#findComment-1209054 Share on other sites More sharing options...
chaseman Posted May 1, 2011 Author Share Posted May 1, 2011 That is quite complex, is there no easier way, I actually wanted to use it for a Wordpress theme, to degrade a jQuery navigation bar to a CSS navigation bar. Depending on if JS is enabled or not it will use the corresponding css file. Quote Link to comment https://forums.phpfreaks.com/topic/235280-how-to-check-if-javascript-is-diabled/#findComment-1209070 Share on other sites More sharing options...
jj-dr Posted June 7, 2011 Share Posted June 7, 2011 I found this priceless piece of code. It detects whether javascript is disabled in your browser, and if so it can refresh to or redirect to an alternate javascript-safe page. This is great because now you don't have to worry about using javascript or how you code it, as long as you are willing to create an alternate page for that 3-5% user population that may have javascript disabled (our using a browser that does not support it). You must place the script in between the <head></head> tags of your page. Here's the code: <head> <!--Re-Direct if javascript is disabled on browser--> <noscript> <meta http-equiv="refresh" content="6; URL= myalternatepage.php"><!--THIS IS ALL YOU NEED--> <center><p><table cellpadding="0" cellspacing="0" border="0" width="550" class="redirect"> <tr><td width="100%" valign="top" class="redirect"><p>Your browser does not support JavaScript or you have javascript disabled.</td></tr> <tr><td width="100%" valign="top">You must re-enable JavaScript for a richer experience of this site</td></tr> <tr><td width="100%" valign="top"><b><p>You will be redirected to a javascript-safe website in about 5 SECONDS!</b></td></tr> <tr><td><a href="http://www.plus2net.com/javascript_tutorial/enable_javascript.php" target="_blank"><p>Learn how to enable javascript</a></td> </table> </noscript> <!--END Re-Direct if javascript IS DISABLED--> </head> It all happens in a single line of code, enclosed by the <noscript>tag: <noscript> <meta http-equiv="refresh" content="6; URL= myalternatepage.php"> </noscript> Then you can add any html valid code to let the users know of what's happening (This is optional). Also, you can change the refresh time you want the message to be displayed before it jumps to the new no javascript page. This No Script code will alert visitors about being redirected to a new page. This comes in especially handy for web designers and developers using javascript/jQuery/AJAX. So now your site can be as dynamic and sleek as you want it to be. Good Luck! Quote Link to comment https://forums.phpfreaks.com/topic/235280-how-to-check-if-javascript-is-diabled/#findComment-1226468 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 7, 2011 Share Posted June 7, 2011 Just put the CSS bar in the <noscript> tags... if they have javascript turned on it won't use what's between the tags. If they don't, it will. Quote Link to comment https://forums.phpfreaks.com/topic/235280-how-to-check-if-javascript-is-diabled/#findComment-1226478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.