3

I was talking with a friend about users who do not have javascript enabled in their browser and what could be done to show them a "no-javascript" version of your website.

Is it possible and how can it be done?

Thoughts?

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
Meta
  • 1,830
  • 6
  • 24
  • 28
  • 2
    @BalusC: Probably you're right, but how did you conclude that the single occurring JavaScript in the title was more important that the twice occurring Java in the body? – Daniel Vassallo May 30 '10 at 23:08
  • 1
    I think @BalusC is working on this badge :) http://meta.stackexchange.com/questions/30965/can-we-have-a-mind-reading-badge – Daniel Vassallo May 30 '10 at 23:09

7 Answers7

16

Don't try to build separate JS and non-JS versions of the site. Build a non-JS version and then enhance it with JS. This makes it easier to reuse code, allows you to use object/feature detection for the entire stack, and makes it less likely that users without JavaScript will be left behind if developers update one branch of the site but not the other.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 1
    No disrespect, but the "enhancements" you're talking about are going to be of a disappointingly low order. Either that or you are just going to aim low from the start. Otherwise, you're *still* going to wind up with what is essentially two different versions of the site, both of which will have to be maintained. – Robusto May 30 '10 at 23:39
  • 3
    With respect to Robusto, It's not really 2 versions of the site. It's a working site, *always*, but with extra *features* for javascript users. Mr. Dorward's advice is spot-on and jibes with years of hard-earned usability data. It makes the site more fault tolerant and, in my experience, easier to maintain. – Brock Adams May 31 '10 at 01:05
7

If you mean javascript, look up the <noscript> HTML tag.

Skip Head
  • 7,580
  • 1
  • 30
  • 34
4

If you are talking about JavaScript and want an alternate version of your site for those without, simply give them site without and put this at the top of your page:

<script type="text/javascript">
     location.replace('http:javascript-version-of-your-site');
</script>
Gabe
  • 84,912
  • 12
  • 139
  • 238
  • 1
    The reverse is better - you can avoid the redirect by having the more common scenario be the default. see my comment below. – x0n May 30 '10 at 23:39
  • The meta refresh option is also a good idea, but may not be as search engine friendly, and may cause problems with the browser's "back" button, and some browsers that let you disable JS still ignore `noscript` elements. – Gabe May 31 '10 at 00:32
1

Like this:

<html>
<head>
<noscript>
<meta http-equiv="refresh" content="0;url=http://foo/noscript.htm" />
</noscript>
</head>
<body>
...

The meta refresh (declarative redirect) only gets executed if there is no script enabled on the browser. Of course, the noscript tag is only understood by browsers that have a javascript engine. If you're trying to catch browsers that have NO javascript at all (I don't know of many) then this won't work.

x0n
  • 51,312
  • 7
  • 89
  • 111
  • Some browsers with JS engines will ignore the `noscript` tag, but then not execute any JS when it's disabled, leaving the page nonfunctional. – Gabe May 31 '10 at 00:34
  • 1
    The noscript element is not allowed as a child of the head element, and meta elements may not be children of the noscript element. http://www.w3.org/TR/html4/interact/scripts.html#h-18.3.1 – Quentin May 31 '10 at 08:24
  • Oh, the w3 recommendations. Recommendations, not rules. If HTML was strictly enforced, the world wide web would be a good deal smaller. – x0n May 31 '10 at 18:57
1

I use this combination of JavaScript and CSS

<html>
<style type="text/css">
    .js-on
    {
        display: none;
    }
    .js-off
    {
        background: red;
        color: White;
    }
 </style>
 <div id='jsdetect' class='js-off'><b>Javascript is OFF</b></div>
 <script type="text/javascript">
    document.getElementById('jsdetect').className = 'js-on';
 </script>

</html>

It's useful if your only aim is to tell the users that Javascript is not available and that the site will not work.

Igor Zevaka
  • 74,528
  • 26
  • 112
  • 128
0

You can put some code to log/track/alert you about users who have JavaScript disabled by using the tag.

<noscript>
   // Do Something
</noscript>
Zachary
  • 6,522
  • 22
  • 34
0

Another option open to you rather than the obvious noscript tag is to use JavaScript to drop a cookie, and then test for that cookie and deliver content appropriately. javascript ver vs non redirect or span

just thought I'd throw that in there..

Webby
  • 2,655
  • 5
  • 26
  • 34