A little bit of everything…
RSS icon Home icon
  • Requiring JavaScript to be enabled

    Posted on July 8th, 2009 Aleix 1 comment

    JavaScript LogoThere are many JavaScript scripts in this blog, and those related with AJAX also involve the use of this language. So I thought that it would be useful to know, when implementing such scripts in a site, how to deal with users who do not have JavaScript enabled in their browsers (or rather requiring them to enable it).

    The following code has a very simple goal: to tell them that JavaScript is necessary to browse the page. To do this, the <noscript> tags are used: their content will only be displayed when JavaScript is disabled, or in the rare case the users browser is outdated and does not support client-side scripting.

    
    <html>
    
    <head>
    <title>JavaScript required</title>
    </head>
    
    <body>
    <div id="javascript"><script type="text/javascript">
    <!--
    document.write('Your JavaScript is enabled!')
    // -->
    </script>
    <noscript>
    <p>You must enable JavaScript to see this page.</p></noscript>
    </div>
    </body>
    
    </html>
    
    <html>

    <head>
    <title>JavaScript required</title>
    </head>

    <body>
    <div id=”warning”><script type=”text/javascript”>
    <!–
    document.write(’Your JavaScript is enabled!’)
    // –>
    </script>
    <noscript>
    <p>You must enable JavaScript to see this page.</p></noscript>
    </div>
    </body>

    </html>

     

    One response to “Requiring JavaScript to be enabled”

    1. Hello Aleix,

      Nice information!

    Leave a reply