Javascript – let PHP know that a user does not have javascript enabled

javascriptPHP

Can I let PHP know that a user does not have javascript enabled?

Best Answer

Start by assuming javascript is off or not available, then send the client some HTML which includes this

<script>
window.location = "http://www.mysite.com/javascript.php?enabled=true";
</script>
<noscript>
possible tell the user the consequences of not having javascript enabled

</noscript>

In the javascript.php script, you can store in the session that the client supports javascript. You could also do with with an XMLHTTPRequest object rather than a straight redirect.

However, depending on your application, it's almost always better to build your app to work without Javascript, perhaps less efficiently, and then have your script kick in and augment the basic version with enhanced functionality. That way, you don't need to detect it, you just use it if its available.