Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Some IE but not others?

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
0
0
US
I have this simple little JavaScript code that is loaded as an external file on all my documents. However, one system that I tried it on consistantly has JavaScript errors in Internet Explorer with each and every file. Other systems with the same version of NT and Service Pack level and the same version of Internet Explorer do not have the popup errors. Does anyone see anything in this code to account for it? I'm also loading a CSS file on each HTML file, does the order that the JavaScript and CSS files are being loaded matter?

The first line returns a specific URL if the file is loaded by itself rather that from the menu and the rest minimizes the right-mouse popup. This has me pulling out my hair because the exact same code it working fine on another site but with an NT Server. The problem is with a Unix server, though I don't know what that could have to do with it.

Thanks!
Don

[tt]
<!--//

if (top == self) self.location.href = &quot;
document.oncontextmenu = function(){return false}
if(document.layers) {
window.captureEvents(Event.MOUSEDOWN);
window.onmousedown = function(e){
if(e.target==document)return false;
}
}
else {
document.onmousedown = function(){return false}
}

// -->[/tt]
 
Try to remove the two comments at the beginning (<!--//) and at the (//-->) end of the script.

Bye!
 
Thanks! Actually I have already tried that and the current version does not have the comments. Still no difference. The errors mostly say there is a syntax error on line 1 (sometimes they say it's on line 0!) and ask me if I want to debug. When I answer yes, my error 500 HTML file is what appears in the debugger. Strangely, this happens only on my computer here in the office but not at home, even though a quick JavaScript error appears in the status bar below for an instant at home.

Don
 
It appears to be the if (top == self)

In trying to load the script by itself in a browser, an error says &quot;top&quot; is undefined. How do I define it?

I'm using the exact same code on another site, but on an NT server, and it works fine!

Don
 
This situation is very strange!
So, the &quot;bad&quot; line is this one:
if (top == self) self.location.href = &quot;
The first thing I would try to do, is delete the second &quot;;&quot; from the code.
The second is find what is &quot;top&quot;. If top is not defined somewhere (if it is not a variable or an object) is normal to get an error, because top doesn't exist.

Try, on the machine where the code works fine, to see what top is, with the code
if (top == self) self.location.href = &quot;alert(top);

If top is only a variable, alert() will show the value, if it is an object you will see &quot;[object]&quot; in Explorer and the type of object in Netscape.
If it is an object, use the extended notation in the code.

Bye!
 
In a well-formed (ie, syntactically correct) HTML page, the top object should always exist.

do this at the top of your script to verify that the object exists:
<script>
alert(top)
</script>

do you get a popup window that says [object]?

If you can post a pointer to a url we can look at, or post your complete code here, it will be easier to help.
 
Thanks for the replies!

The complete code is what I posted above and it is being called from an external file. I'm not sure what you mean, Nick, by &quot;top&quot; object in a well formed HTML page. The HTML page has all the proper header, meta and body tags and the JavaScript file is being called from within the head tags. Is that what you meant?

The first line of the code is not related to the rest of it in function obviously (they do two different things), but if I comment out the first line, then the next part gives a similar error where it starts &quot;document.contextmenu&quot; It says &quot;document&quot; is undefined while now it is saying that &quot;top&quot; is undefined.

The URL is - the error will popup if JavaScript debugging is enabled in IE. Otherwise, a very brief error will appear in the status bar at the bottom of the browser in IE or Netscape, which also happens on each and every link.

Strangely (as I said), I am using the exact same code on an NT Server without any problems at all but the Unix server is where it is causing grief. But DeCa, neither have &quot;top&quot; defined anywhere as far as I can tell. I added the code to each site but did not add anything else to either one.

I think the second &quot;;&quot; was just an unfortunate typo on the posting since it is not in my code.

Don
 
Don,
You you have any HTML tags, HTML comment delimters, or anything else in your external javascript file that is not javascript? I know you said you removed the comment delimters.
I went to your page, and got a javascript error. I saved the source on my system, and created a .js file with the code you posted above, but without the comments. It ran fine.
 
Hi Nick,
Strangely, it also runs fine on my NT system at home and here in the office when loaded locally (and also on an NT Web Server). The file I pasted in above is all there is. Although I now have the JavaScript errors turned off in IE, I still see &quot;Error On Page&quot; in the status bar. I removed all other comments etc. earlier so just to be clear, it is as it is now with the correct URL:

[tt]
if (top == self) self.location.href = &quot;
document.oncontextmenu = function(){return false}
if(document.layers) {
window.captureEvents(Event.MOUSEDOWN);
window.onmousedown = function(e){
if(e.target==document)return false;
}
}
else {
document.onmousedown = function(){return false}
}
[/tt]

The extra semi-colon seems to appear in tek-tips but it is not on the file itself. Even using [tt] [/tt] tags around the code, the extra semi-colon is here when I preview the posting and when I post it. Must be a flaw or bug in the tek-tips system.

Don
 
Thanks! I just noticed that the second part of the script DOESN'T work without the comments! The first line and the second part were from two different sources but for some reason, the second part seems to need the comment, though I can't imagine why. It's really only the first line that I care about. The second one is there just because I thought it was interesring.

Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top