SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question detecting if javascript is turned off

    Hi,

    could someone help me in figuring out how to detect if javascript is turned off.

    Im guessing one could do it with javascript because javascript is a client-side language, but if the javascript is turned off wont it never be executed to check if the javascript is turned off?

    Hopefully, someone can help me with this perplexing problem. And i know that one should not design their site necessarily based on js and i have the content and structure if js is off, but i just want to make sure so that everything that can be displayed with the js is displayed if js in on.

    I hope i didn't confuse anybody. And please reply with any questions, comments, concerns, or solutions

    Thanks in advance and Regards,
    Team 1504

  2. #2
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If JS is on, then the JS will run. If JS is off, then it will not run. The only thing you can do for people without JS on is add a few <noscript> tags with alternate content.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Agree with JesseDPate. Anyway, you always shoud provide a fallback scenario in case js is turn off. But this is not a major problem. Few peoples have js off.

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johnny.dacu View Post
    Few peoples have js off.
    Except for the 69+ million people using Firefox and NoScript.

    https://addons.mozilla.org/en-US/firefox/addon/722/

    And that is just considering ONE scenario.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    69+ downloads doesn't mean 69+ computers with noScript installed. I bet half of downoad ar just for testing this addon or same user downloaded twice and so on... noScript doesn't mean js turned off.

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    A simple example of using JavaScript itself to detect if it is or isn't enabled:

    Code:
    <p>JavaScript is <b id="script">not </b>supported.<p>
    <script type="text/javascript">
    document.getElementById('script').style.display = 'none';
    </script>
    If JavaScript is turned off then the word "not" appears in that paragraph. If it is enabled then that word doesn't appear.
    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="^$">

  7. #7
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the help. I am going to do some research in the noscript tags?

    I know this isnt the html forums but
    Do u guys have any advice to go along with using them?

    Or are there any noteable html5 changes in noscript tag?

    Thanks for all your help and Regards,
    Team 1504

  8. #8
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by johnny.dacu View Post
    69+ downloads doesn't mean 69+ computers with noScript installed. I bet half of downoad ar just for testing this addon or same user downloaded twice and so on... noScript doesn't mean js turned off.
    Statistics show that anything between 5-10% of all Internet usage involves a user or browser or device which has scripting either unavailable or disabled. As for NoScript, it DOES mean JavaScript is turned off, that's the whole point of the extension... to cripple scripting unless specified as an exception.

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by team1504 View Post
    Thanks for all the help. I am going to do some research in the noscript tags?
    The <noscript> tag basically became unnecessary about 6 years ago. Since then it has required less code to omit those tags and use JavaScript to hide the content if JavaScript is enabled. This also has the benefit that you can hide inline content whereas the noscript tag is a block level tag. It also has the benefit that you can test if specific JavaScript commands are supported rather than just whether JavaScript itself is available and so still present the static content to those who have a browser that doesn't have a sufficiently up to date version of JavaScript for your script to work.

    My earlier example in this thread showed using JavaScript to hide one word if JavaScript is enabled. The code to do the same thing using the noscript tag involves about twice as much code.

    The one exception to noscript being useless would be wrapping it around some CSS in the head of the page. You can't do that with HTML 4 since noscript is currently only valid in the body. HTML 5 has expansded the use of noscript to allow it in the head and will presumably disallow its use in the body as a future amendment to the draft.
    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="^$">

  10. #10
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Thank you guys for your help.

    As i might have mentioned before, i made a carosel for my site so that the intro, 360 view, and some pictures are rotated as content for the home.
    with your help and without using the <noscript> tag, I reconfigered the js so that no matter when javascript is disabled, be it before or while the carosel is running, then it will display the first slide which is the introduction and does not need javascript to run.
    In other words.
    Slide 1: no js needed
    if js is disabled then everything past this does not happen.
    transition:js needed
    Slide 2:js needed
    transition:js needed
    Slide 3: no js needed and is not essential content.

    Regarding what felgall said here:
    HTML 4 since noscript is currently only valid in the body. HTML 5 has expansded the use of noscript to allow it in the head
    Then the way to make your document html5 is by changing the doctype correct?

    Also, I agree i have not seen noscript is a a while, that is why i forgot about it, but I swear i have seen it in html4 documents. Anyway, I too concur that it should only be used in the head where all <script> and <link< tags ought to be.

    Thanks for all your help, again!

    Regards,
    Team 1504

    P.S. for anyone reading this thread: I found this useful regarding the noscript tag

  11. #11
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    i just realised something..

    My script does not work in IE because it uses css3 so is there a way that one could disable js if the browser is detected as IE using code?

  12. #12
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    There's Conditional Compilation, it would work for Internet Explorer only (so if their using IE, the script won't do anything - kinda like conditional comments), but it won't work for other browsers, and you REALLY don't want to go down the road of having browser specific JavaScript (it's the pinnacle of unprofessional).

    http://www.javascriptkit.com/javatut...lcompile.shtml
    http://msdn.microsoft.com/en-us/libr...fs(VS.80).aspx

  13. #13
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by team1504 View Post
    . Anyway, I too concur that it should only be used in the head
    Just remember that <noscript> is only valid in the <head> with HTML 5. In HTML 4 it is only allowed in the <body> (where it is useless).

    The best place to put script tags is immediately before the </body> tag where they will not slow the loading of the rest of the page.
    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="^$">


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
  •