Hi there,
This is our problem:
We write a new page xyz to the current browser window by using the well known command sequence
[CODE]document.open();document.write(xyz);document.close();
.
If now the string [FONT=Courier New]xyz[/FONT] itself contains a javascript tag which references an external JS file Γ la
[CODE]<script src=”http://somewhere/extern.js”></script>
, further [FONT=Courier New]document.write()[/FONT] commands, contained in the xyz string or even in the external JS will be extecuted by the browser not until the complete xyz page was processed.
This means that the output of those [FONT=Courier New]document.write()[/FONT] commands will not reach the proper location inside the xyz page. The Internet Explorer sticks them to the end of the page, while Firefox as its predecessor Netscape4, shifts in – as well known – a [FONT=Courier New]document.open()[/FONT] before the delayed [FONT=Courier New]document.write()[/FONT] effecting that the output is brought onto a new blank page. (Secondary Firefox sits there on the blank page waiting for a [FONT=Courier New]document.close()[/FONT] which will never come from us since we never caused this [FONT=Courier New]document.open()[/FONT] π‘ )
This should demonstrate the above:
— File ‘loader.html’ —-
[CODE]<html>
<head>
<script language=”JavaScript”>
function writeNewPageIntern()
{
document.open();
document.write(‘<html><body><h1>WrittenPage Title</h1><hr><script language=”JavaScript”> document.write(“dynamic contents (inside string)”)</script><hr></body></html>’);
document.close();
}
function writeNewPageExternJS()
{
document.open();
document.write(‘<html><body><h1>WrittenPage Title</h1><hr><script language=”JavaScript” src=”http://localhost/test/extern.js”></script><hr>end of page</body></html>’);
document.close();
}
function writeNewPageExternJSIntern()
{
document.open();
document.write(‘<html><body><h1>WrittenPage Title</h1><hr><script language=”JavaScript” src=”http://www.no-such-server.ddr/halb/Cgi/extern.js”></script><script language=”JavaScript”> document.write(“dynamic contents (inside string)”)</script><hr>end of page</body></html>’);
document.close();
}
</script>
</head>
<body>
<h1>LoaderPage Title</h1>
<form action=”javascript:writeNewPageIntern()”><input type=”submit” value=”writeNewPageIntern()”></form>
<form action=”javascript:writeNewPageExternJS()”><input type=”submit” value=”writeNewPageExternJS()”></form>
<form action=”javascript:writeNewPageExternJSIntern()”><input type=”submit” value=”writeNewPageExternJSIntern()”></form>
</body>
</html>
— File end —
— File extern.js —
[CODE]document.write(“dynamic contents (extern JS)”);
— File End —
The first function ([FONT=Courier New]writeNewPageIntern()[/FONT]) is successful and demonstrates that recursive calls of [FONT=Courier New]document.write()[/FONT] are troublefree.
The second function [FONT=Courier New]writeNewPageExternJS()[/FONT] shows the problem with document.write() commands in the external JS file. [I](Please adjust in [FONT=Courier New]writeNewPageExternJS()[/FONT] the location of the external JS file on your system.)
The third function [FONT=Courier New]writeNewPageExternJSIntern()[/FONT] demonstrates that recursion is broken for Mozilla even if the external JS can not be found.
Has anyone already encountered such behaviour?
A straight-forward workaround could consist in preloading the external JS files somehow in strings and insert them into the xyz string before we do our [FONT=Courier New]document.write(xyz)[/FONT]. ? We will try this now and maybe I’ll post later whether this helps.
Best regards
Semmel