1. Home
  2. Computing & Technology
  3. JavaScript

My Script Doesn't Work

If you have pasted a JavaScript into your web page and the script doesn't work then the first thing you need to determine is whether it is that script that is broken in itself or whether it is something else in your page conflicting with the script that is stopping it from working.

The simplest way to check is to set up a minimal web page and paste the script into that to see if it will work there. If the script works in the minimal page then you can slowly add sections of code to slowly convert it back to the full page testing as you go to see which piece of the rest of the page it is that is breaking the script. If the script doesn't work in a minimal web page then you know that it is the script itself that is broken.

So what exactly is a minimal web page? It is a web page with the minimum of content needed to actually be a web page in the first place. The code for our minimal web page lo0oks like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Test</title>
</head><body>
</body></html>

All you need to do with the minimal web page is to save it as test.html and paste your script into it following the instructions on how to install the script into a web page. This basically gives us a web page which contains effectively nothing except the script that doesn't work when added to your regular web page. Since the rest of your web page isn't in this test.html file if the script doesn't work when pasted into this page you know that the problem is either something in the script itself or that you are adding it into the wrong place in the page. If it does work in the test.html page then you know that the script is failing because of a conflict with something else in the page.

Either way you have reduced where you need to look to find out what is causing the problem.

Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.