tags:

views:

63

answers:

4

Is it possible to do checking and verification of JavaScript state in a browser ?

+3  A: 

No, not reliably. But it is possible to respond with something (on the client) if Javascript is not available using noscript:

<noscript>Your browser does not support JavaScript!</noscript>
karim79
+1  A: 

Is there any reason you need to do this via PHP, instead of displaying a message in the browser using the NOSCRIPT tag?

Justin Ethier
yes, i need them to be one of basic condition how to display template and its feature. All html code that will be include into a php page (for example, index.php) based on the state of javascript
justjoe
+3  A: 

That's the wrong way to do it. PHP should be outputting markup that works with JavaScript off, and you should be enhancing that markup with JavaScript. I suggest you read up on progressive enhancement.

cpharmston
More on that subject: http://icant.co.uk/articles/pragmatic-progressive-enhancement/#build
David Dorward
+1  A: 

At the top of your index.php you could do something like

<script type="text/javascript">
    window.location = '/index_with_js.php'
</script>

So, if the browser had JS enabled, it would be redirected to a special index page, which could in turn set a session variable, e.g. $_SESSION['has_js'] = true;

If the browser doesn't have JS enabled, the page won't be directed, so $_SESSION['has_js'] won't ever be set.

eclipse31