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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Define function NS6.2

Status
Not open for further replies.

Dragonfish

Programmer
Joined
Apr 25, 2001
Messages
62
Location
UG
Hi,

Netscape 6.2 is complaining that a function is´nt defined - and I can´t figure out what the f... wants. I´ve been programming for IE and want to include NS. Here´s what I´ve got:

index.html ...

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title>Test Browser</title>
<meta name=&quot;author&quot; content=&quot;gullever&quot;>
<meta name=&quot;generator&quot; content=&quot;Ulli Meybohms HTML EDITOR&quot;>
<script language=&quot;JavaScript&quot; src=&quot;index.js&quot; type=&quot;text/javascript&quot;></script>
</head>
<body onLoad=&quot;main()&quot;>
</body>
</html>

calls index.js...

function main(){
document.write(&quot;Just a Test<br>&quot;);
browser_check();
}

function browser_check(){
alert(&quot;in Browser check area&quot;);
}

Using IE both the document.write(&quot;Just a Test<br>&quot;); and alert(&quot;in Browser check area&quot;); are ok
Using NS the document.write(&quot;Just a Test<br>&quot;); is ok but alert(&quot;in Browser check area&quot;); causes an error - browser_check is not defined. If things don´t work at this level then programming for NS looks like it could be a nightmare - appreciate the help - DavidinGermany
 
The way I'm understanding it document.write(&quot;Just a Test<br>&quot;); overwrites that page with that text....

If you look at the source in IE all you will see is:

Just a Test<br>

Perhaps because the function browser_check(); is called after document.write has overwritten the page it is giving the error?
 
Thanks KevinAR18,

I´ve tried the same thing with an alert - NS6.2 just does´nt call browser_check(); (says it is´nt defined???) and IE does. This thing is so elementary I´m just baffeled.

DavidinGermany
 
Change places of the statements in main():

function main(){
browser_check();
document.write(&quot;Just a Test<br>&quot;);
}

and it'll be OK. Tested in Opera, IE5, N4 and N6.2
By some reason both Netscapes doesn't like alert() being called after document.write().

Later, if you change alert() to some other statement (like another document.write) you can go back to the original order.
 
Here's a quote from that page:
&quot;Use the write method within any SCRIPT tag or within an event handler. Event handlers execute after the original document closes, so the write method implicitly opens a new document of mimeType text/html if you do not explicitly issue a document.open method in the event handler.&quot;
You are essentially overwriting all the html on your page when you call document.write.
From what I can tell NS6/Mozilla cannot access any other functions for the simple reason document.write has already erased the whole page and any functions along with it.

I hope I'm correct. :) I couldn't really find some definite info the confirm this.

If you put the alert inside the same function as document.write it will work. I'm thinking the reason for this is because the function has been loaded into memory and is thus able to finish any commands inside it as a result.

function main(){
document.write(&quot;Just a Test<br>&quot;);
document.write(&quot;Just a Test<br>&quot;);
alert(&quot;in Browser check area&quot;);
}
 
Thanks guys!

Problem sorted out. Yesterday I was standing at the edge of an abyss, now it looks like I´m one step further.

DavidinGermany
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top