2

Like "Facebook", I want to disable all of my website content if "JavaScript" is disabled. When JavaScript is disabled Facebook only shows a message .

"JavaScript Required We're sorry, but Facebook doesn't work properly without JavaScript enabled. If you can't enable JavaScript try visiting the mobile-optimized website. "

Now what i'm trying to do is, if anyone disable JavaScript, they will only be able to show a message, nothing else. How can I do that?

MI Sabic
  • 327
  • 5
  • 17
  • 1
    possible duplicate of [How to detect if JavaScript is disabled?](http://stackoverflow.com/questions/121203/how-to-detect-if-javascript-is-disabled) – Raghav Sood Apr 07 '15 at 05:24

4 Answers4

6

this will redirect to javascriptNotEnabled.php

 <noscript><h3> You must have JavaScript enabled in order to use this order form. Please 
      enable JavaScript and then reload this page in order to continue. </h3> 
      <meta HTTP-EQUIV="refresh" content=0;url="javascriptNotEnabled.php"></noscript>
YesItsMe
  • 1,629
  • 15
  • 30
1

How??

What you should do is create a div that fills the entire page using html and css, then right after window.onload, remove that div

<div id="nojs" style="width:100%;height:100%;position:fixed; background-color:white;">
   <h1>Enable JavaScript!</h1>
</div>
<script>
   window.onload = function () {
       document.getElementById('nojs').parentElement.removeChild(document.getElementById('nojs'));
   }
</script>

noscript doesn't can't disable the whole page as far as I am concerned

Fiddle while JSFiddle doesn't work without JavaScript, the code still is an example

Community
  • 1
  • 1
Downgoat
  • 12,910
  • 5
  • 40
  • 68
0

PHP is a server-side and can't analyze such settings of your browser.

But, You can just use javascript <noscript> tag to do this

The <noscript> tag defines an alternate content for users that have disabled scripts in their browser or have a browser that doesn't support script.

Read more about <noscript> from the w3 resource here

<script>
document.write("Hello World!")
</script>
<noscript>Please enable JavaScript!</noscript>
Sulthan Allaudeen
  • 11,158
  • 12
  • 49
  • 62
0

load the site contents via javascript.

Your page should look like:

<html>
    <body>JavaScript Required We're sorry, but Facebook doesn't work properly without JavaScript enabled. If you can't enable JavaScript try visiting the mobile-optimized website.</body>
    <script>
        document.getElementByTagName("body").innerHTML = "";
    </script>
    <script src="loadPage.js"></script>
</html>
Patrick Gunderson
  • 3,255
  • 15
  • 28