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.
Page 1 of 5 123 ... LastLast
Results 1 to 15 of 61
  1. #1
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post

    Post make document/ website viewable only when JavaScript is enabled

    Hello,

    I would like to know how to make a website (in this case, a parent div) viewable only if JavaScript is enabled?

    I tried to develop a code that can do this, but could not find the solution.
    Code:
    <html>
    <head>
    <script type="text/javascript">
    window.onload=function()
    var="true"
    if(JavaScript.enabled)
    {
    document.getElementById('true')
    }
    OnClick()
    {document.getElementById('toggle').onclick=function()
    	{document.getElementById('jahava').style.display=(document.getElementById('jahava').style.display!='none')?'none':'';}}
    </script>
    </head>
    <body>
    <noscript>You must have JavaScript enabled to view the website.</noscript>
    <div id="jahava">Contents Here</div>
    </body>
    </html>
    Element ID

    Webs Support Helper

    Your friendly neighborhood Taroman.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Making it way too hard.

    Code:
    <html>
    <body>
    <div id="nojs">Sorry, you can't view this page if JavaScript isn't enabled</div>
    <div id="contents" style="display: none;">
    ... your normal contents here ...
    </div>
    <script type="text/javascript">
    document.getElementById("nojs").style.display = "none";
    document.getElementById("contents").style.display = "block";
    </script>
    </body>
    </html>
    If JavaScript isn't available and enabled, then the "contents' will never get displayed. But the "nojs" will.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    defencedog (03-04-2012)

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,277
    Thanks
    10
    Thanked 581 Times in 562 Posts
    i use css for this:

    Code:
    <html>
     <head>
      <style> .nojs #jahava {display:none;} </style>
     </head>
     <body class="nojs" onload='document.body.className="loaded" '>
      <noscript>You must have JavaScript enabled to view the website.</noscript>
      <div id="jahava">Contents Here</div>
     </body>
    </html>
    Last edited by rnd me; 02-29-2012 at 05:58 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    620
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by Old Pedant View Post
    Making it way too hard.
    Just to cover all bases, what if CSS is also disabled?

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,607
    Thanks
    6
    Thanked 997 Times in 970 Posts
    Write the entire DOM with JavaScript.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,277
    Thanks
    10
    Thanked 581 Times in 562 Posts
    Quote Originally Posted by jalarie View Post
    Just to cover all bases, what if CSS is also disabled?
    fine.
    Code:
    <head>
    
    <script type='text/javascript'>document.write("<st"+"yle>"); </script>	
    <meta http-equiv="refresh" content="0;url=http://google.com/">
    <style></style>
    
    </head>
    patent pending hack of mine...



    or, use my crypto app, but hard-code the password by defining a PW string var of the password:
    Code:
    <html> <script>PW="defaultPassword";  eval( unescape( "function%20jcipher%28p%2Cs%29%7Bvar%20i%3D0%2CP%3D0%2CK%3D0%2Cb%3D%22%22%2CMax%3D0%2Cd%3D%5B%5D%3Bif%28p.slice%280%2C3%29%3D%3D%22zz%2C%22%29%7Bvar%20slen%3Ds.length+1%3Bd%3Dp.split%28%22%2C%22%29%3Bp%3D%22%22%3Bvar%20junk%3Dd.shift%28%29%2CScc%3DString.fromCharCode%3BMax%3Dd.length%3Bvar%20tr%3D%5BMax%5D%3Bfor%28var%20i%3D0%3Bi%3CMax%3Bi++%29%7BP%3Dd%5Bi%5D%3BK%3Ds.charCodeAt%28i%25slen%29%3Btr%5Bi%5D%3DScc%28P%5EK%29%3B%7Dreturn%20tr.join%28%22%22%29%3B%7Dreturn%20false%3B%7D%0A" ) ); 
    var enc='zz,44 ,0,10,13,26,64,126,90,40,83,4,24,26,30,0,32,8,12,13,4,85,24,27,112,10,29,28,0,79,26,11,119,68,17,9,65,24,13,31,53,65 ,18,83,0,10,16,23,105,16,0,70,73,28,2,84,36,9,26,0,87,12,19,23,101,72,69,7,65,5,13,6,53,15,7,83,19,6,4,77,32,18 ,12,3,22,20,14,24,53,65,28,29,27,22,82,13,102,68,47,7,23,20,63,23,34,8,3,7,87,6,1,68,101,10,4,4,13,16,8,75,90,107 ,58,83,3,29,27,1,100,68,17,9,65,17,9,2,53,13,28,3,87,14,82,7,111,0,0,70,21,29,13,0,112,2,18,29,87,11,29,68,116,12 ,12,21,77,85,14,1,36,65,16,28,2,3,22,68,110,11,17,70,7,28,2,16,112,21,27,22,87,28,29,8,117,16,12,9,15,91'
     if (typeof PW == 'undefined'){var PW = prompt('Enter The Password for this Document:')};
     if (PW.length){  document.write( jcipher(enc, PW)); };
    </script></html>
    (changes from generated output in red). i made this a document to demo, but you can place that script bock into the parent div to conceal only part of a document.
    this works with css, works with meta refresh blocking, and requires js to even read the source by any human.
    Last edited by rnd me; 03-02-2012 at 08:14 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    There isn't really any purpose served by trying to obfuscate the code since the final HTML that it generates is easy to view regardless using either one of the development tools or a simple piece of JavaScript.

    There also isn't really any reason for preventing those who have JavaScript disabled from accessing the page unless you are just too lazy to create a version of the page that will work for everyone. If you do want to drive those without JavaScript away from your page along with their friends and their friends then a simple "Go Away you are not welcome here" message in place of the content of your site will effectively produce the same end result (except slightly quicker).

    It is unlikely that anyone with CSS disabled will have JavaScript enabled. It is far more likely that someone will override your CSS and/or JavaScript with their own.

    You should only use document.write if you need to support Netscape 4 and earlier (although even by the time Netscape 4 was released it was considered extremely poor practice to have pages that don't work when JavaScript isn't available).

    The only sites where it makes sense to have pages that actually rely on JavaScript to work are those on sites that are actually about JavaScript and anyone visiting a site about JavaScript with JavaScript disabled or not available in their browser at all wouldn't be expecting all the script examples to work in their browser.

    Apart from animations, anything that can be done with JavaScript can also be done without it and the reason why a large number of people actually disable JavaScript is because they visit too many sites that have annoying animations.

    Those who don't have JavaScript enabled can be divided into two groups - those who are using a browser without JavaScript who therefore can't turn it on and those who have deliberately disabled it for a reason and who therefore will NOT turn it on just because some site owner was too lazy to set up their site properly to work without it.

    You may get away with a JavaScript only site if it is only intended for you and a few friends to use but you certainly can't get away with it for a business site (as one retailer discovered after being fined several million for not having a site that worked without JavaScript and which was therefore found to be discriminating against disabled people).
    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.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by felgall View Post

    You may get away with a JavaScript only site if it is only intended for you and a few friends to use but you certainly can't get away with it for a business site (as one retailer discovered after being fined several million for not having a site that worked without JavaScript and which was therefore found to be discriminating against disabled people).
    An urban myth, surely! If you can prove this, please supply a reference. I doubt that even in enlightened Australia it is a criminal offence to have a site which does not work without Javascript.

    When I Google for "Javascript discrimination" I get many links that tell me that I must have Javascript enabled to view them! Including The Gay and Lesbian Rights Lobby.

    Edit: Researching, I find that in 2000, an Australian blind man won a court case against the Sydney Organizing Committee of the Olympic Games (SOCOG). This was the first successful case under Disability Discrimination Act 1992 because SOCOG had failed to make their official website, Sydney Olympic Games, adequately accessible to blind users. Presumably he went on to sue book and newspaper publishers on the same grounds! I rather think that Javascript or lack of it was not an issue in this case. I suspect that he was not totally blind, but visually impaired, perhaps colour-blind.

    IMHO people who deliberately disable Javascript in their browsers (a tiny minority surely?) must know perfectly well what they are doing, and should be prepared to accept the consequences. Same with those who insist on clinging to Netscape 4! If I disable Javascript in my browser that does not somehow make me disabled.
    Last edited by Philip M; 03-03-2012 at 11:14 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by Philip M View Post
    An urban myth, surely
    It was one of the big department stores in the USA sued by a blind person who was unable to use their site to make purchases because the site required JavaScript and the site was impossible to navigate with JavaScript enabled if you couldn't actually see the site. It was settled out of court for some undisclosed amount that is believed to be in the hundreds of thousands or millions. The store web site was also quickly changed so it would work for blind people so as to prevent a recurrence. It happened about two or three years ago.

    The Gay and Lesbian Rights Lobby is not a business and so would not be subject to the rules regarding preventing people with disabilities from being allowed to buy products from them.

    Studies have shown that over 70% of web users are disabled in some way although most of the disabilities are so minor that they can be compensated for by simple things such as zooming pages to make the text big enough to read or overriding the stylesheet with one that doesn't use the colours that the person cannot distinguish between.

    Somewhere between 6 and 10% of web users have JavaScript disabled. In some cases it is because the browser or web reader being used doesn't support JavaScript. More common perhaps is all the people who have got fed up with ad after ad after ad after ad and silly animation after silly animation and who have therefore deliberately turned it off to get rid of all the garbage. The more knowledgeable of those have their browser set so that JavaScript is only enabled on those sites they regularly visit where the script actually serves a useful purpose (this the statistics show they have it disabled but they actually have it enabled for some sites).

    You can get away with a site that doesn't work without JavaScript providing that you are not a business selling to the public. For a business there is the risk of being sued (assuming that the people without JavaScript along with their friends and their friend's friends don't simply switch to buying from the competition. For other sites requiring JavaScript simply means that you have instantly lost at least 6% of potential visitors and possibly several times that (depending on how many friends those who can't use the site have and how widely the message that the site is a heap of excrement actually spreads). After all for almost any web site there are dozens of alternative sites some of which will work without JavaScript that everyone can use instead of the one that is broken for some visitors.
    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.

  • #10
    New Coder
    Join Date
    Feb 2012
    Location
    England
    Posts
    59
    Thanks
    12
    Thanked 2 Times in 2 Posts
    This post is redundent as I read the above one :P How can I delete my posts?

  • #11
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,277
    Thanks
    10
    Thanked 581 Times in 562 Posts
    Quote Originally Posted by felgall View Post
    You may get away with a JavaScript only site if it is only intended for you and a few friends to use but you certainly can't get away with it for a business site (as one retailer discovered after being fined several million for not having a site that worked without JavaScript and which was therefore found to be discriminating against disabled people).
    disabled people can run javascript. javascript greatly enhances accessibility and it's cousin usability. If a site is inaccessible, it's usually because of image text, plugins, and poor dom structure (lack of <Hx>s, <nav>, <img alt>, role=, or using <meta refresh=0>, etc).

    now let me be clear: it is possible to reduce accessibility with javascript. many widgets are not keyboard-navigable as are navs that use jQuery().hover(), client-side redirects, harsh validation, and others gotchas.


    That being said, as far as content goes, ajax injecting new static content is just as or more accessible than "regular" pages. <video> pumping captions to a div for screen-reader announcement is far more accessible than flash captions inside a black-box. ARIA form and control states provide a lot more info to AT than CSS, but they need javascript to be updated after page-load. Often, javascript is used to replace plug-ins with poor accessibility, and that's a clear win for accessibility.


    Just like HTML, javascript is a tool that can build something accessible or inaccessible, it depends on how it's used. There is nothing intrinsically inaccessible about javascript itself.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #12
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by felgall View Post
    You may get away with a JavaScript only site if it is only intended for you and a few friends to use but you certainly can't get away with it for a business site
    Well, that is interesting because either:

    1) You are telling a blatant lie.

    or

    2) You are displaying your incompetancy by not getting your facts straight first before posting

    or

    3) My legal adviser at the ATO has been lying to me when he informed me that I am under no legal obligation to provide full functionality to javascript disabled browsers and that I am not liable in any way to users with javascript disabled.

    I seem to recall that you made similar comments/generalisations on another website. I have sent a copy of your posts, name and contact details to my legal adviser and asked him to investigate if what you say is true for my particular case and if not, to take what ever legal action he feels is appropriate.
    Last edited by webdev1958; 03-04-2012 at 02:28 AM.

  • #13
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,607
    Thanks
    6
    Thanked 997 Times in 970 Posts
    Look whoís chiming in! Long time, no see, bullant.

    Anyway, in response to Philip Mís opinion:
    Quote Originally Posted by Philip M View Post

    IMHO people who deliberately disable Javascript in their browsers (a tiny minority surely?) must know perfectly well what they are doing, and should be prepared to accept the consequences. Same with those who insist on clinging to Netscape 4! If I disable Javascript in my browser that does not somehow make me disabled.
    I have several minor websites registered with a free StatCounter account which is logging a maximum of 500 hits. On the currently most popular site of these, of the 500 hits it shows 9 without JavaScript. On the other sites it shows between 0 and 7 hits out of 500 without JS. I installed a new one recently with just 72 hits and there are 7 without JS.

    OK, it might be very low in percentage, and hits are not equal to unique visitors (one visitor can make several hits, or several hits can come from one visitor only, respectively) but shows that itís certainly possible that people browse without JS. I donít see any reason to exclude them, especially when itís not a lot of additional effort to provide proper accessibility.

  • #14
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    [ot]
    Quote Originally Posted by VIPStephan View Post
    I donít see any reason to exclude them, especially when itís not a lot of additional effort to provide proper accessibility.
    Only if the client is willing to pay for the additional work. If they aren't, I am under no obligation, legal or otherwise, to provide it.
    [/ot]

  • #15
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by webdev1958 View Post
    [ot]


    Only if the client is willing to pay for the additional work. If they aren't, I am under no obligation, legal or otherwise, to provide it.
    [/ot]
    If they are not prepared to pay the extra then why put the extra effort in to creating the JavaScript version. The version that works without JavaScript is always much easier to build - just not as quick and convenient for those with JavaScript enabled to use.

    Only where the client is prepared to pay for the extra effort should you be creating the JavaScript version. There is no legal obligation to create a web page at all. There is a legal obligation in some countries for business sites to ensure their site is usable for ALL their visitors. Mostly it is a matter of wanting people to actually visit the site and so you build it so that it functions for all visitors because that's the best way to avoid getting a reputation for creating garbage web sites.

    The only web site known to have been actually sued for it not working without JavaScript was the US store that settled out of court for a sum believed to be somewhere between 100,000 and 10,000,000. All other sites that require JavaScript usually just have everyone ignore that site and go to their competition instead. No one ever hears about them because no one bothers to visit them.

    There are also lots of people writing garbage that they think is JavaScript that actually makes the site harder to use - that's why so many people disable JavaScript. If all the JavaScript were actually written properly then there'd be no reason for anyone to disable it. It takes several years for even an experienced programmer to learn how to write JavaScript properly so most of what is written is better suited to Netscape 2 than it is to modern browsers.

    Just consider how much supposed JavaScript you see that contains any of the following long dead code:

    language="javascript"
    document.write
    document.all
    eval
    alert
    prompt
    navigator.userAgent

    any of those is a clear sign that the person who wrote the code has not learnt JavaScript but has just copied something that someone else wrote over 10 years ago.

    Anyway, your legal advisor can't force people to visit crap web sites so their opinion is irrelevant.
    Last edited by felgall; 03-04-2012 at 07:10 AM.
    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.


  •  
    Page 1 of 5 123 ... LastLast

    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
    •