Hi!

I don't know if this has been answered already and a search gave to many results.

I have a website that is built with ASP.NET and that uses some javascript.
When I run a debug on localhost to check for errors the ASP.NET code works just fine, but every single piece of javascript code generates some kind of error on a OnClick event.

The specifik error is not important. What is important is that it is an error.
When I publish to a dedicated webserver the javascript does yields no errors what so ever.

I have done a few google searches and the few hits that I got with this problem gave no answers, just a few lame excuses that the security settings may be to high or something like it.

Now, I have tried this with a very low setting with the same result.
So. What's the difference, besides this being localhost, between a webserver on localhost and a webserver on a server?
And why do I, and others, get a javascript error only on localhost?

I'm running IIS on both with identical configurations.

Recommended Answers

All 6 Replies

If you are using IE7, this post might help you in some way.

Actually, I don't. I'm using IE6.
And it's not the security popup.
What I get is the yellow triangle with a black exclamationpoint, in the statusbar of the browser, stating that this-or-that is undefined.

Then the only option left would be to debug your script and see what exactly is causing the 'undefined' problem. A quick google search for IE debugging can give you some leads.

It's possible that browser is unable to "import" all/any/some of the javascript files. If I were you I would:
a. install Firefox
b. install Webdeveloper Toolbar extension/add-on
c. install Firebug extension
d. Restart Firefox
e. Open the page in question
f. On the Webdeveloper Toolbar click on Information > View Javascript

Make sure you see all the expected javascript files. You will be able to tell very clearly if any of them is missing.

g. IF all the files are there, on the lower right-hand side of the screen you will see a little firebug. Click on it and report here what error details it gives you.

Well. FireFox showed a few errors, like "error in string" (or something like that).
But when I added a check for browser type to solve the DOM differences between IE and FF, the errors vanished.

Before:

var appTable = document.getElementById("appTable");
var a = document.createElement('<div id="a' + appInc + '">');
appTable.appendChild(a);

After:

var appTable = document.getElementById("appTable");
if (navigator.appName == "Microsoft Internet Explorer") {
            var a = document.createElement('<div id="a' + appInc + '">');
} else {
            var a = document.createElement('div');
            a.setAttribute("id", "a" + appInc);
}
appTable.appendChild(a);

Whatever I did. This now works on localhost without errors. Weirdness.
So I suppose that this issue is resolved. I guess. Unless anyone has something to add that explains this?

This:
var a = document.createElement('<div id="a' + appInc + '">');

is a Microsoft weirdness. The correct way to do it crossbrowser is exactly like you have it in your else case. The create element is supposed to receive only the name of the tag ("div") not an HTML string ("<div id=''>").

An alternative (shorter form) to the else case is as follows:
var a = document.createElement('div');
a.id="a" + appInc;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.