When running this code in IE7:
function insertScript() {
var newScript = document.create Element('script ');
newScript.type = "text/javascript";
var s = document.create TextNode("alert ('hi');");
newScript.appen dChild(s); // problem line
document.getEle mentById("myDiv ").appendChild( newScript);
}
window.onload=i nsertScript;
I get this error:
Unexpected call to method or property access
And a pointer that points to the newScript.appen dChild(s) line.
Am I using createTextNode incorrectly or is IE7 getting it wrong?
The function, as written, works correctly in FF2.0, Opera9 and AIUI,
Safari1.3.2 Its an attempt to get around Safari not supporting the
setting of the .text property of a script element. If IE7 simply won't
create the text and append it then feature testing for createTextNode
won't work. So, I came up with the idea of attempting to set the .text
property with a variable definition then reading that variable. If it is
set, then use the .text property. If it isn't set, then use
createTextNode. Not sure how reliable it is so I thought about using an
IE conditional to isolate IE and go based on that but it reeks of
browser detection.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
function insertScript() {
var newScript = document.create Element('script ');
newScript.type = "text/javascript";
var s = document.create TextNode("alert ('hi');");
newScript.appen dChild(s); // problem line
document.getEle mentById("myDiv ").appendChild( newScript);
}
window.onload=i nsertScript;
I get this error:
Unexpected call to method or property access
And a pointer that points to the newScript.appen dChild(s) line.
Am I using createTextNode incorrectly or is IE7 getting it wrong?
The function, as written, works correctly in FF2.0, Opera9 and AIUI,
Safari1.3.2 Its an attempt to get around Safari not supporting the
setting of the .text property of a script element. If IE7 simply won't
create the text and append it then feature testing for createTextNode
won't work. So, I came up with the idea of attempting to set the .text
property with a variable definition then reading that variable. If it is
set, then use the .text property. If it isn't set, then use
createTextNode. Not sure how reliable it is so I thought about using an
IE conditional to isolate IE and go based on that but it reeks of
browser detection.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Comment