RichardL said:
>
>The following script from http://msdn2.microsoft.com/en-us/library/ms533897.aspx
>runs fine in HTML-Kit 1.0.0.292 and IE 7.0, but not in Firefox
>2.0.0.4.
>
>In Firefox, it opens a blank page, but does not present the "Click
>Me" button. I suspected the "DEFER" attribute might be a Microsoft-
>only invention, but removing it did not improve the situation.
>
>Any ideas?
>
><head>
> <title>EmbeddingScriptExample</title>
> <script type="text/javascript">
> function insertScript(){
> var sHTML="<input type=button onclick=" + "go2()" + "
>value='Click Me'><BR>";
> var sScript="<SCRIPT DEFER>";
> sScript = sScript + "function go2(){ alert('Hello from
>inserted script.') }";
> sScript = sScript + "</SCRIPT" + ">";
> ScriptDiv.innerHTML = sHTML + sScript;
> }
> </script>
></head>
>
><body onload="insertScript();">
> <DIV ID="ScriptDiv"></DIV>
></body>
>
If you're not seeing the button, you've typed it in wrong.
When I copy and paste your code, being careful to repair the
wrapped lines, I see the button in the same version of Firefox.
When clicked, nothing happens, but when I look at the Error
Console, I see the expected message: "go2 is not defined".
If you want it to actually work, you should use DOM methods
instead of using innerHTML to add script. You should really
use DOM in place of innerHTML, period, but I've just replaced
the script portion:
<html>
<head>
<title>EmbeddingScriptExample</title>
<script type="text/javascript">
function insertScript(){
var ScriptDiv=document.getElementById("ScriptDiv");
var sHTML="<input type='button' onclick='go2()' value='Click Me'><BR>";
ScriptDiv.innerHTML = sHTML;
var scriptEl=document.createElement("script");
scriptEl.setAttribute("type","text/javascript");
scriptEl.text="function go2(){ alert('Hello from inserted script.') }";
ScriptDiv.appendChild(scriptEl);
}
</script>
</head>
<body onload="insertScript();">
<DIV ID="ScriptDiv"></DIV>
</body>
</html>
--