SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    Non-Member
    Join Date
    Aug 2007
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Disable Message

    Hiya,

    Is there anyway of notifying to the user they they have JavaScript turned off?

    TicTac

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TicTac View Post
    Hiya,

    Is there anyway of notifying to the user they they have JavaScript turned off?

    TicTac
    Code:
    <noscript>
    <span style='color:#fff;background-color:#f00;font-weight:bold;text-decoration:blink;padding:0.5em'>JavaScript is Disabled on your system</span>
    </noscript>
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Logic Ali: You should use a block-level element rather than a SPAN, since the snippet you posted isn't valid with a Strict DTD. In this case, <p>…</p> seems appropriate.

    @TicTac: If you have to display a message like this, you should consider starting over. Progressive enhancement is a much better method: build the page so that it works without JavaScript first, then add JavaScript enhancements (unobtrusively).

    That way, people with JavaScript disabled or unsupported (which may not be their own decision) will not notice anything wrong, while those with JavaScript enabled get a better experience.
    Birnam wood is come to Dunsinane

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    There is no longer any need for the <noscript> tag. The HTML contains what you want people without JavaScript to see and simply hide anything that is not needed when JavaScript is available using JavaScript.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    Non-Member
    Join Date
    Aug 2007
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you display an error message if JavaScript is turned of if you hav'nt go an <noscript> tag?

  6. #6
    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)
    You don't need one. Having javascript off shouldn't cause an "error", it should just provide a less colourful, though not less functional, experience. However, if you really insist on it (bad) and your page cannot possibly function without javascript (bad) and you want to inform the user of this (bad), you create your paragraph with the apologetic text in it and then hide it with javascript. That way anyone with javacscript off will see it and for those with javascript it will be hidden. However, I'd like to point out that this is a bad (bad) idea. Like the above posters said, progressive enhancement is the way forward.

  7. #7
    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 TicTac View Post
    How do you display an error message if JavaScript is turned of if you hav'nt go an <noscript> tag?
    Code HTML4Strict:
    <p id="nojs">If you see this, you don't have JavaScript.</p>
    <script type="text/javascript">
      var p = document.getElementById("nojs");
      p.parentNode.removeChild(p);
    </script>
    But not having JavaScript is not an error. Designing a page that requires JavaScript is an error.
    Birnam wood is come to Dunsinane

  8. #8
    Non-Member
    Join Date
    Aug 2007
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Disable Message

    Isn't it easier just to you the <noscript> tag?
    I'm for simplicity.

    TicTac

  9. #9
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, <noscript> is easier. I just answered your question.

    Both methods are bad, though.
    Birnam wood is come to Dunsinane

  10. #10
    Non-Member
    Join Date
    Aug 2007
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Disable Message

    Have you got a thing about using JavaScript?
    What do you use then?

    TicTac

  11. #11
    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 TicTac View Post
    Have you got a thing about using JavaScript?
    Not at all. Only about relying on it.
    Birnam wood is come to Dunsinane

  12. #12
    Non-Member
    Join Date
    Aug 2007
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What would you not use it for?

  13. #13
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's far easier to describe what I would (and do) use it for.

    I use JavaScript to enhance the usability of a page.

    It can be to perform client-side form validation, for performance reasons. You mustn't rely on this, but have the main validation server-side, but doing it client-side if supported enhances the usability.

    It can be to use an Ajax solution to populate chained select boxes, like choosing country/region/city. It would still work without JavaScript, but it would require a round-trip to the server for each choice. Using JavaScript it can be faster and improve usability.

    It can be to provide toggle features, e.g., hiding lengthy code examples to reduce scrolling for users with JavaScript enabled.

    The only time I use JavaScript in such a way that the page doesn't work without it, is on our intranet where I know that it's supported and enabled.
    Birnam wood is come to Dunsinane


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
  •