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 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Only display if JS is enabled

    The navigation for the web site I'm doing requires JS to remotely work so I want to make some kind of back-up scenario. Basicly, how can I make it so my main navigation will only display if there is script?

    One thought I had was put it in a div, hide it in the CSS, then use JS to show it but if there is a better way to do this I'd like to know.

  • #2
    New Coder
    Join Date
    Apr 2012
    Posts
    25
    Thanks
    13
    Thanked 1 Time in 1 Post
    You can use PHP to do this.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,919
    Thanks
    6
    Thanked 1,040 Times in 1,013 Posts
    Quote Originally Posted by Dornith View Post
    One thought I had was put it in a div, hide it in the CSS, then use JS to show it but if there is a better way to do this I'd like to know.
    Well, the best approach would be progressive enhancement; i. e. have the navigation work w/o JS (at least in a very basic state) and then apply a script to enhance it the way you like. But if you have something already the quickest solution might be to use <noscript> to provide a non-JS alternative.

    Would you mind showing us what you have? That makes it easier to determine the best approach.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by VIPStephan View Post
    the quickest solution might be to use <noscript> to provide a non-JS alternative.
    It is just as easy and a lot more flexible to simply use JavaScript to hide the text you don't want to appear when JavaScript is enabled. That way you aren't limited to entire blocks of content.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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