473,608 Members | 2,565 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('','_se lf');
w.document.open ();

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

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

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

function test() {
window.setTimeo ut(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:blan k" name="_displayF rame1" id="_displayFra me1"
border="no" />
<frame src="about:blan k" name="_displayF rame2" id="_displayFra me2"
border="no" />
</frameset>
<frame src="about:blan k" id="ControlFram e" name="ControlFr ame"
border="no" />
<noframes>
</noframes>
</frameset>
</html>

Feb 27 '07 #1
8 3739
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
"shimmyshac k" <ma********@gma il.comwrote in message
news:11******** **************@ j27g2000cwj.goo glegroups.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.goo glegroups.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.ne twrote:
"johnsonlau " <laozhongch...@ gmail.comwrote in message

news:11******** **************@ m58g2000cwm.goo glegroups.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.ne twrote:
"johnsonlau " <laozhongch...@ gmail.comwrote in message

news:11******** **************@ m58g2000cwm.goo glegroups.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.writ e(a.join('')),
whether I invoke close method on top._displayFra mes1.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(f ile) {
var script = "<script language=\"Java Script\" src=\"" + file + "\"></
script>";
document.writel n (script);
}

includeJsFile(" js/const.js");

Feb 28 '07 #8
On 2ÔÂ27ÈÕ, ÏÂÎç11ʱ05·Ö, "shimmyshac k" <matt.fa...@gma il.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="JavaS cript" src="js/jsInclude.js"></script>
<script language="JavaS cript">
function timeout()
{
alert("time out!");
}

function test() {
window.setTimeo ut(timeout, 5000);
}
</script>
</head>
<body onload="javascr ipt: test()">
<span name="test.mess age" id="test.messag e">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.node Type == TEXT_NODE) {
if (docParent != null && ((docParent.nod eName.toLowerCa se() ==
"script") || (docParent.node Name.toLowerCas e() == "title"))) {
docParent.text += xmlNode.nodeVal ue;
continue;
}
docNode = doc.createTextN ode(xmlNode.nod eValue);
} else {
var nodeName = xmlNode.nodeNam e.toLowerCase() ;
docNode = doc.createEleme nt(nodeName);
if (xmlNode.attrib utes != null) {
for (j = 0; j < xmlNode.attribu tes.length; j++) {
var attr = xmlNode.attribu tes[j];
var attrName = attr.name.toLow erCase();
var attrValue = attr.value;
if (attrName == "src" || (attrName == "href" && nodeName !=
"base")) {
attrValue = GetBase(doc) + attrValue;
}
docNode.setAttr ibute(attr.name , attrValue);
if (attrName.subst r(0, 2) == "on") {
var func = new Function(attrVa lue);
docNode[attrName] = func;
}
}
}
}
docParent.appen dChild (docNode);
xmlNode2DocNode (doc, docNode, xmlNode.childNo des);
}
}
function GetBase(doc)
{
var oBaseColl = doc.getElements ByTagName("base ");
return ((oBaseColl && oBaseColl.lengt h) ? oBaseColl[0].href : "");
}

function includeJsFile(f ile) {
var doc = document;
var docParent = doc.getElements ByTagName("head ")[0];
var docNode = doc.createEleme nt("script");
var dir = GetBase (doc);
docNode.src = dir + file;
docParent.appen dChild (docNode);
}

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

var newNode = newDoc.getEleme ntsByTagName("h tml")[0];
if (typeof newNode != 'undefined') {
while (newNode.childN odes.length 0) {
newNode.removeC hild(newNode.ch ildNodes[0]);
}
}
xmlNode2DocNode (newDoc, newNode, content.childNo des);
}

Feb 28 '07 #9

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

Similar topics

14
4104
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 it's being written into the page. Is there a way that I can view what is being placed into the page, instead of, or in addition to the javascript code?
7
2745
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 bug</TITLE> <Script Language="JavaScript"> function load() { var w = window.open('','','');
7
2385
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 of the questions, that form is hidden and the next is displayed. Also, as the user answers each question a "count" variable is updated based on their response. I would like the question to show up on the left side and the answer to show up in the...
11
3093
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 non-trivial exercise. inserting '&lt;' and '&gt;' causes the browser to write the text to the page as literal text rather than as the intended script element. Using escape codes seemed to work (makes it standard compliant) but the text is not written to...
8
5359
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 icon on the top corner keeps running with "loading" message on the bottom status bar even though the browser completed everything in the iFrame. The line that causes the problem is "document.close()" in the included JS file. If this line is...
13
2610
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 all different and mostly way above my competance level to understand (ieg Ajax;-(). Could someone give me some guidance please. - thanks var xmlDoc; // Code for IE if (window.ActiveXObject) { document.write("IE detected<br>");...
5
2963
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 have a script tag, that document.write's some HTML. Like this:
7
8959
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 document.write to send output to the browser. This javascript file contains some html code and another script tag. The execution order in Internet Explorer (6&7) appears to be different than that of browsers such as FireFox. Example:
1
3808
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"> <!-- var strBGCol = "#ADCED7"; document.write("<table border='0' width='100%' cellpadding='0' cellspacing='0'>"); document.write("<tr>");
0
7998
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8470
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8329
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6813
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6010
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3959
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2472
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1327
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.