Friday, May 4, 2012

HTML/ASP.NET - How to check if JavaScript disabled without JavaScript function

Using JavaScript function to check if JavaScript is disabled and display message stating so may some time corrupt other JavaScript or JQuery stuff on our page.
Before I was using this structure:



    <script language="javascript" type="text/javascript">
        window.onload = function () { document.getElementById('entire_content').style.display = ''; };
    </script>

<form id="form_01" runat="server">
<div id="entire_content" style="display:none;">
My content
</div>
</form>
 <noscript>
JavaScript is disabled!
</asp:Panel>
But after today I'm using much simpler approach:

<form id="form_01" runat="server">
<div id="entire_content">
My content
</div>
</form>

<noscript>
    <style type="text/css">
       #entire_content { display:none; }
    </style>
JavaScript is disabled!
</noscript>


Enjoy!

No comments:

Post a Comment