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

Community
  • 1
  • 1

3 Answers3

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/

Lazar Vuckovic
  • 798
  • 9
  • 22
  • can i use `get_broswer` function ? – Mohamed Nagy Oct 01 '12 at 15:04
  • 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. – Lazar Vuckovic Oct 01 '12 at 15:28
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>
mineichen
  • 470
  • 2
  • 11
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.

Silviu G
  • 1,241
  • 10
  • 31