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
  • 367
  • 2
  • 7
  • 18
  • 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

7

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,709
  • 16
  • 32
  • @yesitsme, it's working for me. I have one doubt after enabling the script how to redirect on the previous page? – user9437856 May 04 '18 at 17:06
  • @user9437856 theres a up-vote button, I don't understand your question. – YesItsMe May 04 '18 at 17:18
  • @yesitsme, For example, I am no homepage and My script is disabled. Now I added your above code like so that will redirect on javascript-disable.php page . Now I am on javascript-disable.php page after I enable the script and refresh the page then how to redirect from javascript-disable.php to homepage? – user9437856 May 04 '18 at 17:37
  • Yes, Sure I will do upvote. – user9437856 May 04 '18 at 17:38
  • you're probably looking for this https://stackoverflow.com/a/46498548/4535386 – YesItsMe May 06 '18 at 02:46
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
  • 13,771
  • 5
  • 46
  • 69
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,330
  • 12
  • 48
  • 63
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,263
  • 17
  • 28