PDA

View Full Version : Mozilla won't run external function / Opera hates my layers.


coredumped
09-19-2002, 09:31 PM
I'm having a few problems with my Javascript run I run it under Mozilla 1.0 or Opera 6.04. Under IE6, it works great... but I'm having varied issues with Mozilla and Opera.

To start out, all my Javascript is in seperate '.js' source files. When my page loads, it has three frames, one is used as a 'canvas', and the other two are used to do things in the background. My Javascript functions are all loaded into one of these hidden frames.

When the frame loads, it calls a function called 'initSite()', where site data is initialized, and ultimately the site is rendered to the 'canvas' frame.
Inside the 'initSite()' function, I call another function, 'setSiteName()', which resides in a seperate .js file, but is still called in the frame:




<HTML><HEAD><TITLE>Background Frame 1</TITLE>
<SCRIPT LANGUAGE="javascript" SRC="js/scripts1.js"></SCRIPT>
<SCRIPT LANGUAGE="javascript" SRC="js/scripts2.js"></SCRIPT>
</HEAD>
<BODY onLoad="javascript:initSite();">
</BODY>
</HTML>


Above, 'initSite()' is located in 'scripts1.js'. 'setSiteName()' is located in 'scripts2.js', and is called within initSite():



function initSite()
{
setSiteName("My Site");

...
Some other functions are called down here.
...
}


'setSiteName()', sets a value to a global variable declared within the .js file itself, as shown below.




var _SITE_NAME;

...
Some other functions
...

function setSiteName(siteName)
{
_SITE_NAME = siteName;
}


This is where Mozilla dies. It doesn't give any errors or warnings, it just flat-out refuses to process the setSiteName function. I even tried putting an 'alert' inside the setSiteName function just to see whether it's even going into the function, but it isn't.

To make things a little more confusing, this script DOES work in Opera (to the best of my knowledge thus far), but Opera is complaining about another problem, and the error it gives is actually a little more confusing than those that Internet Explorer provides. :^/

Opera gets through the setSiteName function fine, but right after that function, I begin outputting HTML to the 'canvas' frame. Again, this works in IE6, but Opera doesn't like it.

To continue initSite():


[CODE]

function initSite()
{
setSiteName("My Site");

parent.DISPFRAME.document.write("<HTML><HEAD><TITLE>The Display Frame</TITLE></HEAD>\n");
parent.DISPFRAME.document.write("<BODY BGCOLOR=\"" + getBGColor() + "\" TEXT=\"#FFFFFF\">\n");

...
The rest of the site is displayed using the 'parent.DISPFRAME.document.write' call used above.
...
}
[/CODE[

The error Opera gives me is:


Error:
name: TypeError
message: Value on left hand side of '.' is not convertible to Object:
parent.DISPFRAME.document.body


Now, I realize I haven't used a call like parent.DISPFRAME.document.open(), but I even tried sticking that in and it made no difference. I also attempted
parent.DISPFRAME.document.body.write(...), but to no avail.

Anyone have any idea as to why these errors are occurring and how to potentially fix them?

Thanks,

- coredumped.

brothercake
09-20-2002, 12:06 AM
document.body is only a valid object in IE; it will not work in Mozilla or Opera

jkd
09-20-2002, 12:42 AM
Originally posted by brothercake
document.body is only a valid object in IE; it will not work in Mozilla or Opera

document.body works fine in Mozilla, as long as the file is served as text/html. I don't know about Opera.