1

A quick question.. searched across the web but could not find the solution of my question

  1. First how I should detect that user has JavaScript enable/disabled in browser.
  2. If disabled show a message, hide page or do something to prevent showing the content.

Regards

Sharif

Amjad
  • 1,950
  • 5
  • 26
  • 41
  • Hide the actual content and show the "Not available" message by default, and use JS to show the real content? – Teemu Jun 18 '14 at 11:59
  • I know Mr Amir... if you've not understood my question fully please read it again... I've checked everything before submitting this post – Amjad Jun 18 '14 at 11:59

3 Answers3

3

noscript blocks are executed when JavaScript is disabled, and are typically used to display alternative content to that you've generated in JavaScript, e.g.

<noscript>
    <b>Your JavaScript is disabled, please enable it </b><a href="#">Instructions</a>
</noscript>
Subodh Ghulaxe
  • 18,333
  • 14
  • 83
  • 102
2

Use <noscript> tags; this website is actually a good example of that.

<noscript>
    <div id="noscript-warning">Stack Overflow works best with JavaScript enabled</div>
</noscript>

And with CSS, make it more obvious

#noscript-warning { 
background-color: #AE0000;
color: #FFFFFF;
font-family: sans-serif;
font-size: 120%;
font-weight: 700;
left: 0px;
padding: 5px 0px;
position: fixed;
text-align: center;
top: 0px;
width: 100%;
z-index: 101;
}

You could, of course, put it in the center (possibly with position: fixed) to prevent anyone doing anything with the page.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
1

First set message as page is when no javascript is avaible. Then after load when will be JavaScript availbe run function that will hide message of not avaible JavaScript. If there wont be JavaScript avaible message will last.