-1

I was puzzled with a question. Many browsers like Internet Explorer allows to disable the javascript.

How do I check through whether the user's Browser has disabled javascript or not?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Umesh Patil
  • 10,475
  • 16
  • 52
  • 80
  • 1
    What are you using the check for? It doesn't make sense to check if a user's browser has Javascript enabled, since that would require a programming language like Javascript to be enabled. You could use some `noscript` trickery though. – Waleed Khan Feb 22 '13 at 15:28
  • Why do you need to detect? If you are trying to change CSS, a common way is to have a class on your body, `nojs` or something, and then remove it with JavaScript. – Brad Feb 22 '13 at 15:28
  • 2
    http://stackoverflow.com/questions/121203/how-to-detect-if-javascript-is-disabled – marekful Feb 22 '13 at 15:28

4 Answers4

2

An approach that e.g. modernizr uses is that you set a class no-js and modernizr then removes that class after finishing.

pdu
  • 10,295
  • 4
  • 58
  • 95
1

In addition to pdeurstler's answer, there is an old school way.

It is tad old school but, <noscript>...</noscript> detects JavaScript being disabled and executes the embed HTML.

Starx
  • 77,474
  • 47
  • 185
  • 261
1

A common solution is to the meta tag in conjunction with noscript to refresh the page and notify the server when JavaScript is disabled, like this:

<!DOCTYPE html>
<html lang="en">
    <head>
        <noscript>
            <meta http-equiv="refresh" content="0; /?javascript=false">
        </noscript>
        <meta charset="UTF-8"/>
        <title></title>
    </head>
</html>

In the above example when JavaScript is disabled the browser will redirect to the home page of the web site in 0 seconds. In addition it will also send the parameter javascript=false to the server.

A server side script such as node.js or PHP can then parse the parameter and come to know that JavaScript is disabled. It can then send a special non-JavaScript version of the web site to the client.

Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
0

Just have some text that says you need javascript to use the site, then onload destroy that text with javascript.

Zachrip
  • 3,242
  • 1
  • 17
  • 32