0

Possible Duplicate:
Check if JavaScript is enabled with PHP

I need a way to detect if javascript is enabled or disabled in the user-agent in the codeigniter framework

1
  • No duplicate occurred, my question for codeignniter framework where get_browser function not work. Commented Oct 2, 2012 at 12:25

3 Answers 3

1

You cannot detect this directly on the server-side. Please take a look at this article for alternative solutions: http://www.untwistedvortex.com/detect-javascript-enabled-php/

Sign up to request clarification or add additional context in comments.

2 Comments

can i use get_broswer function ?
Here is a copy from the php.net website regarding the get_browser function: get_browser — Tells what the user's browser is capable of. It lets you know if JavaScript is supported on the user's browser, it can't tell you if it's enabled.
1

You don't get this information with the HTTP-headers. But i have a little workaround:

You can store this information in the User-Session. By default you suggest, that JS is disabled. The first delivered Page should execute a Ajax-Call to a script which tells the USER-Session, that Javascript is enabled.

Of course this has some disadvantages:

  • The first Page-Call is allways no-script
  • You don't get the information, if the User suddenly disables Javascript
  • Searching-Engines could rate your page down, if you make big differences between the script- and the noscript version

Some times it is enough to have the information, if JS is enabled or not, in the CSS. You can do it like this:

<head>
    <script type="text/javascript">
        // Jquery version
        $(function() {
            $('body').removeClass('noJs');
        });
    </script>
    <style type="text/css">
        .noJs #hello {
             display: none;
        }
    </style>
</head>
<body class="noJs">
    <div id="hello">Hello</div>
</body>

Comments

0

There is no way to do a reliable detection in CodeIgniter or other framework/plain PHP.

Besides, that information is not part of the standard browser header/user-agent.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.