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);
}