www.webdeveloper.com
Results 1 to 9 of 9

Thread: Is it possible?

  1. #1
    Join Date
    Mar 2009
    Location
    Fortaleza, CE, Brazil
    Posts
    81

    Is it possible?

    Simple question: is it possible not to show the content of a page if Javascript is not activated?

  2. #2
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    The simplest way is to do something like:

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    	<title></title>
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    window.onload = function () {
    	document.body.style.display="block";
    }
    </script>
    <style type="text/css">
    body {
    	display:none;
    }
    </style>
    </head>
    
    <body>
    <div id="oPut">This won't appear until unhidden by JS</div>
    </body>
    </html>
    Another way it could be done;
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    	<title></title>
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function getFile(fileName){
        oxmlhttp = null;
        try{
            oxmlhttp = new XMLHttpRequest();
            oxmlhttp.overrideMimeType("text/xml");
        }
        catch(e){
            try{
                oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e){
                return null;
            }
        }
        if(!oxmlhttp) return null;
        try{
           oxmlhttp.open("GET",fileName,false);
           oxmlhttp.send(null);
        }
        catch(e){
           return null;
        }
        return oxmlhttp.responseText;
    }
    
    window.onload = function () {
    	document.getElementById("oPut").innerHTML = getFile("myContent.txt");
    }
    </script>
    <style type="text/css">
    
    </style>
    </head>
    
    <body>
    <div id="oPut"></div>
    </body>
    </html>
    Since both methods depend on Javascript to show the content the page would be blank if Javascript is disabled.
    54 68 65 42 65 61 72 4D 61 79

  3. #3
    Join Date
    Mar 2009
    Location
    Fortaleza, CE, Brazil
    Posts
    81
    Nice! I didn't think it was possible! Thank you, dude!

  4. #4
    Join Date
    Mar 2009
    Location
    Fortaleza, CE, Brazil
    Posts
    81
    Ok, so, how could I tell the user that Javascript is not activated, thus making the page content not to appear? Not possible, I guess...

    Oh, sorry for double posting.

  5. #5
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330

    Talking

    Try this variation on a theme ...
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    window.onload = function () {
    //  document.body.style.display="block";
      document.getElementById('oPutON').style.display = 'block';
      document.getElementById('oPutOFF').style.display = 'none';
    }
    </script>
    <style type="text/css">
    /* 	body { display:none; } commented out */
    #oPutON { display:none; }
    #oputOFF{ display:block; }
    </style>
    </head>
    
    <body>
    <div id="oPutON">This won't appear until unhidden by JS (JS not enabled)</div>
    <div id="oPutOFF">This will appear until hidden by JS (JS enabled)</div>
    Rest of page...
    </body>
    </html>

  6. #6
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    Could just use the noscript tags, they only show their content if javascript is disabled
    HTML Code:
    <noscript>Javascript is disabled</noscript>
    54 68 65 42 65 61 72 4D 61 79

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330

    Arrow

    Quote Originally Posted by TheBearMay View Post
    Could just use the noscript tags, they only show their content if javascript is disabled
    HTML Code:
    <noscript>Javascript is disabled</noscript>
    I thought those tags were downgraded, declassified, retired or something like that.
    'TheBearMay' has the much easier solution if not.

  8. #8
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    Deprecated ... Pretty sure it hasn't been.
    54 68 65 42 65 61 72 4D 61 79

  9. #9
    Join Date
    Mar 2009
    Location
    Fortaleza, CE, Brazil
    Posts
    81

    Thumbs up

    hm... Yeah, <noscript>, of couse... I had forgotten it.

    Thank you, men!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles