Peter Michaux said the following on 10/18/2006 2:42 PM:
pe**********@gmail.com wrote:
>One Dumm Hikk wrote:
>>On Oct 16, 6:42 pm, petermich...@gmail.com wrote:
First, is this the third or fourth time you have asked this question in
different forms?
Second, why are you making it harder than it has to be?
Because I remember having troubles with this when I tried is previously
and repeating the experiments yesterday means I needed to revisit this.
Safari is the problem.
Ahh, never used Safari (no MAC here) so I can't test it.
>>
>>Ditch these two lines:
var s = document.createTextNode("alert('hi');");
Try adding an alert here to see what s is.
>>> newScript.appendChild(s); // problem line
And do it the way I have always written it for you to do:
newScript.text = "alert('hi')";
Meaning, simply set the script element's .text property with the string
you want to use for the body of the script block.
This does work in Firefox, Opera and IE but does not seem to work in
Safari.
Any ideas about solving this problem?
This is your original function:
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(newSc ript);
}
You create a text node, then append it to the script element that hasn't
been appended to anything, that may be what Safari is balking on. Try
changing the order of your calls:
function insertScript() {
var newScript = document.createElement('script');
newScript.type = "text/javascript";
document.getElementById("myDiv").appendChild(newSc ript);
var s = document.createTextNode("alert('hi');");
newScript.appendChild(s); // problem line
}
Then, the browser actually has an element to appendChild the text node
to. It may work, may not. I don't have a MAC to test it on. If it fails,
your best recourse for Safari testing may be RobG or either Richard
Cornford (They are the only two that I know for sure have access to a
MAC, invariably there are others here, I just don't know about them).
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/