Chris
Chris

Reputation: 6770

How do I debug this weird IE JavaScript Problem

OK,

Here is my problem, I have a master page with a HEAD section that contains my JS includes. I have one JS include

<script src="Includes/js/browser.js" language="javascript" type="text/javascript"></script>

In my page i consume it like this:

<body>
<form id="form1" runat="server">
<div>
....
<script type="text/javascript">registerBookmarkButton();</script>
....
</div>
</form>
</body>

And i get this error:

Line: 216
Error: Object expected

Please tell me i just missed something and it's a stupid mistake

Upvotes: 1

Views: 649

Answers (5)

Ateş G&#246;ral
Ateş G&#246;ral

Reputation: 140050

  1. Try running your code through JSLint.
  2. Add alert() calls here and there to narrow down the error to a particular location.

Upvotes: 1

Vineet Reynolds
Vineet Reynolds

Reputation: 76709

The "Object expected" error occurs when the browser's script engine was expecting to find an object, but was unable to do so. This usually occurs when you try to make a function call, but the function itself is unavailable to the script engine, presumably because you mistyped the function name when calling it.

To successfully debug this error, you must first determine the instruction at the line number reported in the error. This cannot be done by browsing through all the source files, unless you have some psychic debugging powers. It is recommended that the exception be caught inside a JavaScript debugger. If you are debugging this under MS IE, you might want to install Microsoft Script Engine which can be installed with MS Office, or the poor man's Microsoft Script Debugger. For Firefox, there are the excellent Firebug and Venkman extensions. Jonathan Boutelle's blog post on debugging JavaScript in IE seems like a must read.

Upvotes: 0

Mark Renouf
Mark Renouf

Reputation: 30990

If you can use Firefox, I would highly recommend installing and enabling the Firebug addon.

Otherwise, see some of the following for tools that might help:

Upvotes: 2

Vilx-
Vilx-

Reputation: 106920

As you wish.

You just missed something and it's a stupid mistake.

:)

That being said, I'd try to find out which file it is that has the faulty line 216. Perhaps it's the browser.js file? Other possibilities include:

  • You messed up the URL and the file isn't loaded;
  • The function depends on the DOM to be completely loaded, but it's called before the relevant elements are created (most JS should be done after the onload event under normal circumstances).

Upvotes: 2

Related Questions