473,503 Members | 13,285 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.write problem in Firefox

When I use document.write to replace the comment of a frame,
I found that the page was always showing as loading in Firefox
(2.0.0.2).
But it seems that it is OK in IE6.
Could someone help me with this problem?
Thanks.

My file:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script>
function writeWindow (w2) {
var w = w2.open('','_self');
w.document.open();

var a = [
'<html><head><title>No bugs</title>',
'<script language="JavaScript" src="js/jsInclude.js"><\/script>',
'<script language="JavaScript">function timerOut()
{alert("test"); }function t() {var timerObj = new Timer(5000,
timerOut);timerObj.start();}<\/script>',
'</head><body onload="javascript: t()">',
' <h1>It works</h1>',
'<p>Add lots more HTML here...</p>',
'</body></html>',
];

var d = w.document;
w.document.write(a.join(''));
d.close();
}

function load() {
writeWindow(top._displayFrame1);
}

function test() {
window.setTimeout(load, 2000);
}
</script>
</head>
<frameset name="frames" id="frames" cols="1024,0" frameborder="0"
border="0" onload="test()">
<frameset id = "_displayFrames" cols="800,200" frameborder="0"
border="0">
<frame src="about:blank" name="_displayFrame1" id="_displayFrame1"
border="no" />
<frame src="about:blank" name="_displayFrame2" id="_displayFrame2"
border="no" />
</frameset>
<frame src="about:blank" id="ControlFrame" name="ControlFrame"
border="no" />
<noframes>
</noframes>
</frameset>
</html>

Feb 27 '07 #1
8 3724
Oh, it will be fine if I remove all "document.write" in the included
JS file "js/jsInclude.js",
but failed when any one exists in that file.

Is there any way to solve this problem?
Thanks.

Feb 27 '07 #2
On 27 Feb, 13:53, "johnsonlau" <laozhongch...@gmail.comwrote:
Oh, it will be fine if I remove all "document.write" in the included
JS file "js/jsInclude.js",
but failed when any one exists in that file.

Is there any way to solve this problem?
Thanks.
Sheesh, it is a bit of a cludge, anything you do to hack it up to work
is deckchairs on the titanic really. I would accept it's limitations
and concentrate on learning more modern methods - document.write has
been deprecated for years, you are beginning to experience why - like
DOM insertion using standard javascript methods.
Is there after all a reason _why_ you need to include the javascript
rather than simply copy and paste it into the array, which you later
join...
I'm not being mean when I say you are making a rod for your own back
here. Think about how it will feel in 4 months when you need to tweak
this.

Feb 27 '07 #3
"shimmyshack" <ma********@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
Sheesh, it is a bit of a cludge, anything you do to hack it up to work
is deckchairs on the titanic really. I would accept it's limitations
and concentrate on learning more modern methods - document.write has
been deprecated for years, you are beginning to experience why - like
DOM insertion using standard javascript methods.
Is there after all a reason _why_ you need to include the javascript
rather than simply copy and paste it into the array, which you later
join...
I'm not being mean when I say you are making a rod for your own back
here. Think about how it will feel in 4 months when you need to tweak
this.
In general, I agree with your overall theory about causing more stress on yourself but you
are flat out wrong on the document method "write" being deprecated. It is not.

-Lost
Feb 27 '07 #4
"johnsonlau" <la***********@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Oh, it will be fine if I remove all "document.write" in the included
JS file "js/jsInclude.js",
but failed when any one exists in that file.

Is there any way to solve this problem?
Yes, there is, use document.close().

-Lost
Feb 27 '07 #5
On 27 Feb, 14:39, "-Lost" <missed-s...@comcast.netwrote:
"johnsonlau" <laozhongch...@gmail.comwrote in message

news:11**********************@m58g2000cwm.googlegr oups.com...
Oh, it will be fine if I remove all "document.write" in the included
JS file "js/jsInclude.js",
but failed when any one exists in that file.
Is there any way to solve this problem?

Yes, there is, use document.close().

-Lost
Technically Lost is correct of course, document.write can be found in
js1.7 for instance. But it's passé, you can choose to use it if you
like, but back in 2004 when I (belatedly I felt) started using DOM
methods to insert blocks of html into other blocks of html, things got
a whole lot easier, although the w3 methods are a little clumsy
compared to a simple document.write call, they do tend to be a tad
more modular, so for large web apps you just can't beat 'em.

Feb 27 '07 #6
On Feb 27, 3:08 pm, shimmyshack wrote:
<snip>
Technically Lost is correct of course,
That would depend a bit what definition of deprecated you wanted to
use. People certainly do deprecate the use of - document.write -, but
no applicable specification has declared it deprecated.
document.write can be found in js1.7 for instance.
No it can not. JavaScript(tm) abandoned its linkage between the host
environment and the language itself with version 1.4. The -
document.write - method is specified in the W3C HTML DOM (and not
deprecated there).

<snip>
... , although the w3 methods are a little clumsy
compared to a simple document.write call, ...
<snip>

That does not quite work as a comparison, given that - document.write
- is a "w3 method".

Richard.

Feb 27 '07 #7
On 2ÔÂ27ÈÕ, ÏÂÎç11ʱ39·Ö, "-Lost" <missed-s...@comcast.netwrote:
"johnsonlau" <laozhongch...@gmail.comwrote in message

news:11**********************@m58g2000cwm.googlegr oups.com...
Oh, it will be fine if I remove all "document.write" in the included
JS file "js/jsInclude.js",
but failed when any one exists in that file.
Is there any way to solve this problem?

Yes, there is, use document.close().

-Lost
When can I invoke document.close?
I failed in it immediately after w.document.write(a.join('')),
whether I invoke close method on top._displayFrames1.document or the
new created document object through the calling of document.open.
But if I set a 1 second timer to invoke document.close,
the page stopped loading after 1s.
It did solved, but it seems that hard to control the timer.
Is that any good idea to close the document?

My js/jsInclude.js file.
====================================

function includeJsFile(file) {
var script = "<script language=\"JavaScript\" src=\"" + file + "\"></
script>";
document.writeln (script);
}

includeJsFile("js/const.js");

Feb 28 '07 #8
On 2ÔÂ27ÈÕ, ÏÂÎç11ʱ05·Ö, "shimmyshack" <matt.fa...@gmail.comwrote:
On 27 Feb, 13:53, "johnsonlau" <laozhongch...@gmail.comwrote:
Oh, it will be fine if I remove all "document.write" in the included
JS file "js/jsInclude.js",
but failed when any one exists in that file.
Is there any way to solve this problem?
Thanks.

Sheesh, it is a bit of a cludge, anything you do to hack it up to work
is deckchairs on the titanic really. I would accept it's limitations
and concentrate on learning more modern methods - document.write has
been deprecated for years, you are beginning to experience why - like
DOM insertion using standard javascript methods.
Is there after all a reason _why_ you need to include the javascript
rather than simply copy and paste it into the array, which you later
join...
I'm not being mean when I say you are making a rod for your own back
here. Think about how it will feel in 4 months when you need to tweak
this.
I do know that use of document.write is not recommended today, but I
do need this to make the page rewrotten completely in some case.
I've tried the DOM using the function shown as below.
But when I define the body's onload handler, I can't get it invoked on
the document loading process on IE,
whereas it did work in FireFox.
If this could be solved, I will consider use DOM rather
document.write.

================================================== =================
xml data send to the client
================================================== =================
<html>
<head>
<title>Test Title</title>
<script language="JavaScript" src="js/jsInclude.js"></script>
<script language="JavaScript">
function timeout()
{
alert("time out!");
}

function test() {
window.setTimeout(timeout, 5000);
}
</script>
</head>
<body onload="javascript: test()">
<span name="test.message" id="test.message">Test Message1213</span>
</body>
</html>

================================================== =================
script that used to rewrite the page
================================================== =================

function xmlNode2DocNode(doc, docParent, xmlNodes) {
var docNode, xmlNode, attr;
var styleNode;
var i, j;
var attrs = new Array();

for (i = 0; i < xmlNodes.length; i++) {
xmlNode = xmlNodes[i];
if(xmlNode.nodeType == TEXT_NODE) {
if (docParent != null && ((docParent.nodeName.toLowerCase() ==
"script") || (docParent.nodeName.toLowerCase() == "title"))) {
docParent.text += xmlNode.nodeValue;
continue;
}
docNode = doc.createTextNode(xmlNode.nodeValue);
} else {
var nodeName = xmlNode.nodeName.toLowerCase();
docNode = doc.createElement(nodeName);
if (xmlNode.attributes != null) {
for (j = 0; j < xmlNode.attributes.length; j++) {
var attr = xmlNode.attributes[j];
var attrName = attr.name.toLowerCase();
var attrValue = attr.value;
if (attrName == "src" || (attrName == "href" && nodeName !=
"base")) {
attrValue = GetBase(doc) + attrValue;
}
docNode.setAttribute(attr.name, attrValue);
if (attrName.substr(0, 2) == "on") {
var func = new Function(attrValue);
docNode[attrName] = func;
}
}
}
}
docParent.appendChild (docNode);
xmlNode2DocNode(doc, docNode, xmlNode.childNodes);
}
}
function GetBase(doc)
{
var oBaseColl = doc.getElementsByTagName("base");
return ((oBaseColl && oBaseColl.length) ? oBaseColl[0].href : "");
}

function includeJsFile(file) {
var doc = document;
var docParent = doc.getElementsByTagName("head")[0];
var docNode = doc.createElement("script");
var dir = GetBase (doc);
docNode.src = dir + file;
docParent.appendChild (docNode);
}

function createNewDocument (doc, content) {
var newDoc = doc.open("text/html", "replace");
newDoc.close();

var newNode = newDoc.getElementsByTagName("html")[0];
if (typeof newNode != 'undefined') {
while (newNode.childNodes.length 0) {
newNode.removeChild(newNode.childNodes[0]);
}
}
xmlNode2DocNode(newDoc, newNode, content.childNodes);
}

Feb 28 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
4076
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
7
2729
by: Remi Bastide | last post by:
I'm trying to open a blank window and write a message in it. The following page works as expected in IE, but in Firefox the message is not written: <HTML> <HEAD> <TITLE>Document.write...
7
2364
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
11
3079
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a...
8
5352
by: hyejin | last post by:
I have a problem with dynamic iframe and document.close() on Firefox. Below two files create a dynamic iframe by JavaScript. These two samples do not have any problems on IE. But, on Firefox, the...
13
2600
by: Gretsch | last post by:
Re XML, Javascript, IE, Firefox Hi, I have a very simple & small XML file (only 7 variables). The code works for IE, but not for Firefox. I've search around and found lots of alternatives, but...
5
2955
by: SuneR | last post by:
Hi, I am having problems figuring out how to make Firefox behave, and output the HTML I want it to output. The thing I want done is actually quite simple. I have a <labeltag, and inside it, I...
7
8955
by: sj071 | last post by:
I'm little more than a novice when it comes to javascript, and this particular problem has been driving me mad for the past few days... The Problem: I have a javascript file that uses...
1
3801
by: celeroSolutions | last post by:
This code works in my site in IE, but not in FireFox, and I'm stuck as to why! Any ideas? (The image paths are correct, I've tested these.) <script language="javascript" type="text/javascript">...
0
7212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.