SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    noob: javaScript detection and display message

    How do you detect if javaScript is turned on/off and if it off, display a message to activate the javaScript?

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That is what the <noscript> element is supposed to be for, but it's horrible and its usage is not recommended. If javascript is on, whatever you want to do with it will work. Otherwise it won't and you will need to figure out some way to produce a version of what you want to do without javascript, even if it's less pretty or functional.

    Most people who have javascript turned off do that by choice, so displaying a message saying "Please turn javascript on as my application depends on it and I haven't catered for people like you who have decided to turn it off" is just going to annoy them.

  3. #3
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles
    That is what the <noscript> element is supposed to be for, but it's horrible and its usage is not recommended.
    Huh? Who says the usage is not recommended?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    noscript

    AFAIK the noscript tag is specifically intended to be used to render it's content when javascript isn't enabled. Other than that, you could use javascript to replace DOM content when javascript is enabled. But that seems like unnecessary code bloat to me.

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bals28mjk View Post
    Huh? Who says the usage is not recommended?
    Anyone who can design a webpage that will function properly with or without javascript. Having a message that says "You don't have javascript enabled and so therefore my page will not work" is a bit like saying "I'm a bit incompetent at web design and so therefore I am bothering you with this stupid notice in the hope that you will enable javascript. If you don't, then my page won't work because of the aforementioned incompetence."

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    need

    True, javascript should be non-intrusive. But I see nothing wrong with using it to enhance a user's experience. For example, something like showing an expandable "accordian" view for users with javascript vs. a longer scrolling page for those without. That said, I have seen many sites that require cookies to be enabled and a few that require javascript. I guess it depends on whether you can afford to irk a segment of your users.

  7. #7
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    But what you say doesn't require <noscript>. In most cases, javascript animates existing content, adds stuff or hides stuff.

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The <noscript> element is supposed to be used to provide alternate content when the script cannot be executed. It's not meant for rude messages telling people to do something the may not even be able to do (like enabling JavaScript).

    Using <noscript> should be a last resort, because it's not reliable. I may have a browser that supports JavaScript and I may have client-side scripting enabled, but if my company firewall strips out JavaScript code, no script will run – and the <noscript> will also be ignored, since my browser is fully prepared to execute scripts.
    Birnam wood is come to Dunsinane

  9. #9
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles
    Anyone who can design a webpage that will function properly with or without javascript. Having a message that says "You don't have javascript enabled and so therefore my page will not work" is a bit like saying "I'm a bit incompetent at web design and so therefore I am bothering you with this stupid notice in the hope that you will enable javascript. If you don't, then my page won't work because of the aforementioned incompetence."
    So its you who doesn't recommend its usage?

    The way you described it, I pictured a person screaming after reading a small message telling them to turn JavaScript on. I'm sure that's happend at least once, but really it's not a big deal.

    It's bad practice, but the reality is some people rely on JavaScript for site functionality. It's smarter to politely turn the user away than leave them thinking your site is complete trash.

    There's never harm informing someone something they might not know.

  10. #10
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Not just me (I'm nobody in the world of the web) but most people who know anything about web standards and good practices (like the man in green above) will tell you something similar.

    There should be no reason to turn the user away unless you're displaying some animation (or something like that that obligatorily requires javascript) where the primary focus of the page is the animation itself. If the primary focus is some information that is being conveyed, then that can be done without javascript, the only difference being that it'll be less "cool" or you might have to reload the page a few extra times.

    The difference here is between using <noscript> to display the same information that the javascript would be responsible for in a condensed sort of manner, and between using it to tell the user that they don't have javascript enabled and that the website isn't going to work (which in most cases means the architect of the site is incompetent). I'd hazard a guess that in most of the "javascript off" cases (which are few), the user already knows it is disabled (possibly out of choice) and so telling the user this is just going to annoy him/her.

  11. #11
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles
    Not just me (I'm nobody in the world of the web) but most people who know anything about web standards and good practices (like the man in green above) will tell you something similar.
    Does W3C know anything about web standards?

    It's really a matter of personal preference.

  12. #12
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bals28mjk View Post
    Does W3C know anything about web standards?
    The first sentence in that section says,
    The following sections discuss how authors may create documents that work for user agents that don't support scripting.
    (Emphasis mine.)

    I wouldn't consider posting a message that says the user has to enable JavaScript as making the document work without scripting.
    Birnam wood is come to Dunsinane

  13. #13
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    noscript

    I just searched saved pages for the noscript tag. All of the ones I looked at were doubleclick like
    HTML Code:
    <iframe>
      <script>
      </script>
      <noscript>
        <a><img/></a>
      </noscript>
    </iframe>
    In other words, the preference is the more "dynamic" javascript, but if that fails an image link is better than nothing.

    EDIT:
    I was just looking at an IBM tutorial that had this
    System requirements

    You will need JavaScript enabled in your browser.

    You'll need the following tools to follow along with this tutorial:

    XUL SDK
    XULRunner
    One of the developer builds of Firefox 3.0
    But the intended target of the tutorial is developers, not normal users
    Last edited by Mittineague; Oct 24, 2007 at 09:37.

  14. #14
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo
    I wouldn't consider posting a message that says the user has to enable JavaScript as making the document work without scripting.
    I wouldn't consider writing a page that relys on JavaScript. But if I did, letting the user know the site doesn't function correctly with it off would be an option.
    Quote Originally Posted by Mittineague
    I just searched saved pages for the noscript tag.
    You should try a saved search with just the "noscript" keyword without the carrots. Check out the first and second threads that pop up and who the poster is


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •