7

Is there a way to test to see if javascript is enabled to ensure an application that required javascript is not initiated when it is disabled or otherwise not available?

Tim
  • 2,667
  • 4
  • 32
  • 39
  • possible duplicate of [How to detect if JavaScript is disabled?](http://stackoverflow.com/questions/121203/how-to-detect-if-javascript-is-disabled) – Mike Weller Apr 05 '13 at 13:51

6 Answers6

7

There is <noscript>.

strager
  • 88,763
  • 26
  • 134
  • 176
  • 2
    remember the caveat with noscript - even if it is not used, it does not guarantee that javascipt is available or working correctly. You can see this by using Firefox Web Developer to turn off javascript. – Colin Pickard Mar 09 '10 at 10:52
  • @Colin: NoScript users will suffer the same: http://stackoverflow.com/questions/993387/noscript-tag-javascript-disabled-warning-and-google-penalty/993461#993461 – Marcel Korpel Mar 09 '10 at 11:21
5

I tend to use the following way.

1) show an error message per default

<div id="noJS">For use, you need JavaScript enabled. (nice images and perhaps a link to your fav. browser)</div>

2) disable it via javascript and show the main app's container

$("#noJS").hide();
$("#app").show();

If javascript is only needed for e.g. navigation, you should try to deliver a non-js version for non-js users in order to increase your audience.

Phil Rykoff
  • 11,999
  • 3
  • 39
  • 63
3

By default, serve the no-Javascript version. Use Javascript to immediately redirect the user to the Javascript version (which will only work if Javascript is enabled).

strager
  • 88,763
  • 26
  • 134
  • 176
2

The scenario is:

  1. Visitor makes first request to your site
  2. Deliver a page which sets two cookiesl one with javascript, another with your server side language.
  3. Header or Meta redirect to another page for testing.
  4. On test page, check if you received the server delivered cookie to see if cookie support is enabled, and test if javascript cookie was received for JS support enabled.
  5. Enjoy your new found knowledge.
h0tw1r3
  • 6,618
  • 1
  • 28
  • 34
0

Not on initial load. You can try to use tricks like setting a cookie in JavaScript and check it on subsequent requests. The best way is to ensure that your site works without JavaScript, and use JavaScript to provide a better experience.

PatrikAkerstrand
  • 45,315
  • 11
  • 79
  • 94
  • what about applications that explicitly use javascript ie gmail? – Tim Mar 09 '10 at 10:47
  • 5
    @user270797, My Gmail doesn't require Javascript. Gmail has an HTML-only version, which uses Javascript for small added features, such as searching contacts live. – strager Mar 09 '10 at 10:48
0

You could create a page with <noscript> content, and have that redirect using javascript to your actual application

Colin Pickard
  • 45,724
  • 13
  • 98
  • 148