Edit Article

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.



Ad

Method 1 of 5: Create the Code

  1. 1
    Open up a new page in your favorite text editing program or web design program.
    Ad
  2. Detect if JavaScript Is Disabled Step 2.jpg
    2
    Type 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

  1. Detect if JavaScript Is Disabled Step 3.jpg
    1
    Save the above code in a file called "Test.html".
  2. Detect if JavaScript Is Disabled Step 4.jpg
    2
    If you JavaScript is on, you will see a pop-up. If JavaScript is off, you will see a message telling you so.
    Ad


We could really use your help!

Can you tell us about
cooking steak?
Yes
No
cooking steak
how to make a perfect steak
Can you tell us about
muscle spasms?
Yes
No
muscle spasms
how to treat muscle spasms
Can you tell us about
Pinterest?
Yes
No
Pinterest
how to get more followers on Pinterest
Can you tell us about
overlay text?
Yes
No
overlay text
how to put text on pictures
Thanks for helping! Please tell us everything you know about
...
Tell us everything you know here. Remember, more detail is better.
Tips
Provide Details.
Please be as detailed as possible in your explanation. Don't worry about formatting! We'll take care of it. For example:
Don't say: Eat more fats.
Do say: Add fats with some nutritional value to the foods you already eat. Try olive oil, butter, avocado, and mayonnaise.

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.

Did this article help you?
Yes No

Become
an Author!

Write an Article