 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
wakan
Joined: 20 Jan 2005 Posts: 1
|
Posted: Thu Jan 20, 2005 4:26 am create <script> element problem in IE |
|
|
|
Hi,
I'm creating a script tag in this way:
| Code: |
var text = d.createTextNode("show_AS("+row_num+");");
var script = d.createElement("script"); script.appendChild(text);
|
where row_num is a counter...(I'm dinamically adding rows to a table)
in Firefox, this works fine...(I have other big problem in Firefox, but I'll hope to ask later this question of the script tag)
in IE it doesn't work: it says that I can't append text to the script element...
any answer?
thanks in advance
Ciao |
|
kanenas

Joined: 14 Dec 2004 Posts: 191
|
Posted: Tue Jan 25, 2005 12:43 am For IE, use 'text' property of script nodes. |
|
|
|
IE doesn't allow script tags to have children; the 'text' property can be used instead. Try this:
| Code: |
/*...*/
function appendChild(node, text) {
if (null == node.canHaveChildren || node.canHaveChildren) {
node.appendChild(document.createTextNode(text));
} else {
node.text = text;
}
}
/*...*/
var script = document.createElement("script");
script.setAttribute('type','text/javascript');
appendChild(script, "show_AS("+row_num+");");
|
As long as the non-method appendChild is only called on script nodes, you can omit the test of node.canHaveChildren, as it will always be false. I don't know if you're setting the 'type' attribute of the script elsewhere; if not, add that step as above.
Out of curiosity, why do you need to dynamically create the script? |
|
thamizh
Joined: 06 Oct 2007 Posts: 1
|
Posted: Sat Oct 06, 2007 1:29 am Not working |
|
|
|
Hi,
I tried with your way. but still IE is having some problem. It did not accept node.text = scriptContent;
My IE crashed once that particular line is executed.
But in firefox dynamic <script> element creation is working.
I need your answer. this is very urgent. can you help me out?
thanks
- thamizharasu S |
|
kanenas

Joined: 14 Dec 2004 Posts: 191
|
Posted: Mon Oct 08, 2007 1:46 pm Need more info |
|
|
|
What version of IE are you using? What is the source for the script you're using?
Try this (complete) example and tell me if it fails and with what error:
| Code: |
<html>
<body>
<script>
function show_AS(row_num) {
document.writeln("show_AS("+row_num+")<br>");
}
function appendChild(node, text) {
if (null == node.canHaveChildren || node.canHaveChildren) {
node.appendChild(document.createTextNode(text));
} else {
node.text = text;
}
}
/*...*/
var script = document.createElement("script");
script.setAttribute('type','text/javascript');
appendChild(script, "show_AS(1);");
document.body.appendChild(script);
</script>
</body>
</html>
|
Also think about alternatives to a dynamically created script element. Could you accomplish the same task using (e.g.) events? |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
 |
|
|
|
|
|
|
|