How to Detect if JavaScript Is Disabled
Five Methods:Create the CodeUnderstand the CodeInterpret the codeEnd the codeTry it Out
In a web page, having JavaScript in it can greatly enhance the experience for the user. Whether it is used to create pop-ups, or validate form data, it makes the web beautiful. What happens when someone doesn't have JavaScript enabled? You need to be able to detect this, and perform something else. This guide will tell you how to do that.
Steps
Method 1 of 5: Create the Code
-
1Open up a new page in your favorite text editing program or web design program.Ad
-
2Type the following code.
- Please note that for this example, we are using HTML4 Strict and directly placing the JavaScript on the page, rather than including it from an external file.
Code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <TITLE>Test Page</TITLE> <script type="text/javascript"> function popUp() { alert("This is an alert") } </script> </HEAD> <BODY onLoad popUp()> <p>You should see a pop-up.</p> <noscript><p>But unfortunately, you don't have JavaScript enabled.</p></noscript> </BODY> </HTML>
Method 2 of 5: Understand the Code
Code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Method 3 of 5: Interpret the code
Code
<HTML> <HEAD> <TITLE>Test Page</TITLE> </HEAD> </HTML>
Method 4 of 5: End the code
- These tell the browser where the HTML start and ends, where the header starts and ends, and what the page title is.
Code
<script type="text/javascript"> function popUp() { alert("This is an alert") } </script>
- This contains the JavaScript.
<BODY onLoad="popUp()"> </BODY>
- This tells the browser where the body is, and what to do when the page loads (Execute the pop-Up() JavaScript function).
<p>You should see a pop-up.</p>
- This tells the web browser to display this as plain text.
<noscript><p>But unfortunately, you don't have JavaScript enabled.</p></noscript>
- This tells the browser what to do if the browser has JavaScript disabled.
Method 5 of 5: Try it Out
We could really use your help!
cooking steak?

muscle spasms?

Pinterest?

overlay text?

Tips
- As you become a better programmer, you will learn different ways of doing this.
Things You'll Need
- A text editor.
- A web browser.
Article Info
Categories: JavaScript
In other languages:
Español: Cómo detectar si JavaScript no está habilitado, Русский: определить, что JavaScript отключен
Thanks to all authors for creating a page that has been read 8,389 times.
About this wikiHow