Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    168
    Thanks
    32
    Thanked 1 Time in 1 Post

    correct way to design assuming rare chance of javascript being turned off

    With JQuery, It seems that a lot of times, in order to get the proper effects to work, you need a div to be set to display: none as its default.

    With that said, if a visitor for some reason has JS turned off, your website while be pretty much dead. Unless 2 things are done in preparation. I'm not sure which is the best way to do thing:

    1: Add some kind of script to detect if JS is turned off or on. If off, tell the page to use an alternate CSS file?

    or

    2: Use the Jquery itself to first change the div to display: none as a callback to execute the next functions. That way, if JS is turned off, the website content divs will at least display, just without any animation/JQuery functions.


    Any insight on this? *To be honest, I see a lot of high end websites that use jQuery and they don't seem to prepare for the rare scenario of JS turned off.

    Any input would be great. I'm working on a site right now that relies heavily on JQuery for the elegance of switching pages ( fades in, etc) and curious what precautions are suggested, if any.

    I'm not sure what the "right thing" to do is.

    Thanks

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,797
    Thanks
    6
    Thanked 1,023 Times in 996 Posts
    Personally, I’m using the NoScript addon for Firefox and I’m permanently annoyed when websites don’t even care to get the most basic things right. So, I appreciate that you do care and I’m gonna tell you how I’m doing it and what I think the best way would be: I usually add a class to the body element with jQuery and then I use that class in my stylesheet to address the elements.

    For example these are usually the first lines in my script:
    Code:
    if(typeof jQuery != 'undefined') {
      $(function() {
        $('body').addClass('jsenabled');
        // more JS comes here
      });
    }
    So, this way I can have my content and then in the stylesheet I tell the element to look a certain way, and if the .jsenabled class is there hide the element (or make it look differently, or whatever):
    Code:
    #whatever {
      …
      …
    }
    .jsenabled #whatever {display: none;}
    There is one drawback, though: If you have your script in the head of the document and a document with a lot of content (HTML wise) there may be a short time (depending on the speed of the internet connection) where you see the unhidden content since jQuery waits for the DOM to be ready before it applies the special class to the body. You can circumvent that by putting that certain part directly into the HTML (e. g. after the start tag of the body) so it applies the class right after the body element is present (and before the entire DOM has to be loaded). But often this won’t even be necessary, that’s just in some cases where it would be obvious.

    You can see this in perfection on http://klett-cotta.de/home/

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    168
    Thanks
    32
    Thanked 1 Time in 1 Post
    Thanks a lot for that detailed explanation and that website that demo's the function. I had an Idea it was going to be something like that but now, at least I know a good way to do it.

    Thanks a lot!


  •  

    Tags for this Thread

    Posting Permissions

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