I need a code that will do something like this: if a browser's javascript is enabled echo "this stuff" else echo "that stuff" Also, will this work across all browsers? Any help will be appreciated.
I am not sure how many ways there are to make JS and PHP to talk but i would suggest using JS to create a cookie called jsEnable. Then get your php to check if the cookie is set. That way you could do. If(isset($_COOKIE['jsEnable'])){ // cookie set so js is enabled }else{ // not set so no js } PHP: Not sure if this is the best solution but thats what comes to mind.
Since your browser is not automatically sending such information to the web server, it is impossible for PHP to know whether you have Javascript enabled or not. <?php echo "<div id=\"javascript-enabled\">Disabled</div>"; ?> PHP: <script type="text/javascript"> document.getElementById("javascript-enabled").innerHTML = "Enabled"; </script> Code (markup): This might not be the best approach, but it doesn't require you to reload the page and will work on all browsers.
Web Solutions, after I posted here I tried to google this question and they all pretty much said what you have said here. j_o I will try what you have suggested. Thanks for the tip.
In PHP you can figure out of the browser/system combination has the javascript feature by the get_browser() method. If the user has javascript ability but has it disabled, you can use the noscript to send them a message to turn it back on to use your website.
Hi try this : Jquery part - $(document).ready(function(){ $("body").removeClass("noJS"); }); Code (markup): CSS part - body .no-js-content :display none body.noJS .main :display none .no-js-content :display block Code (markup): HTML part - <body class="noJS"> <div class="main"> This will show if JavaScript is activated </div> <div class='no-js-content'> This will show when JavaScript is disabled </div> </body> Code (markup):