P
petermichaux
Hi,
I have tried the following based on suggestions of the best way to
insert JavaScript into a page. This is instead of using eval().
Unfortunately IE says "unexpected call to property or method access"
for the second to last line of my function.
If you know what I've done wrong or how to fix it I would appreciate
the help.
Thank you,
Peter
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert Test</title>
<script type="text/javascript">
function insertScript() {
var newScript = document.createElement('script');
newScript.type = "text/javascript";
var s = document.createTextNode("alert('hi');");
newScript.appendChild(s); // problem line
document.getElementById("myDiv").appendChild(newScript);
}
</script>
</head>
<body onload="insertScript();">
<div id="myDiv">
stuff
</div>
</body>
</html>
I have tried the following based on suggestions of the best way to
insert JavaScript into a page. This is instead of using eval().
Unfortunately IE says "unexpected call to property or method access"
for the second to last line of my function.
If you know what I've done wrong or how to fix it I would appreciate
the help.
Thank you,
Peter
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert Test</title>
<script type="text/javascript">
function insertScript() {
var newScript = document.createElement('script');
newScript.type = "text/javascript";
var s = document.createTextNode("alert('hi');");
newScript.appendChild(s); // problem line
document.getElementById("myDiv").appendChild(newScript);
}
</script>
</head>
<body onload="insertScript();">
<div id="myDiv">
stuff
</div>
</body>
</html>