Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Microsoft example runs in IE7, but not in Firefox

Reply
Thread Tools

Microsoft example runs in IE7, but not in Firefox

 
 
RichardL
Guest
Posts: n/a
 
      07-04-2007
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>

 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      07-04-2007
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>


--

 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      07-05-2007
-Lost said:

>
>Ooo, IE7 doesn't puke on setAttribute?


Apparently not. It was the last line I added, and certainly
isn't necessary, but my IE didn't complain about it.


--

 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      07-05-2007
In comp.lang.javascript message <(E-Mail Removed)
oglegroups.com>, Wed, 4 Jul 2007 21:03:19, RichardL <RichardDummyMailbox
http://www.velocityreviews.com/forums/(E-Mail Removed)> posted:
>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?


Microsoft code is probably designed, where possible, not to run on other
systems.

Use, in Firefox, Tools Error Console and it will tell you exactly
what is first found wrong.

Also, "</SCRIPT" should really be "<\/SCRIPT" .

Don't allow your posting agent to wrap code; read the FAQ.

It's a good idea to read the newsgroup c.l.j and its stale FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
RichardL
Guest
Posts: n/a
 
      07-05-2007
On Jul 4, 7:18 pm, Lee <(E-Mail Removed)> wrote:
> RichardL said:
>
>
>
>
>
> >The following script fromhttp://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>
>
> --


I didn't know about Error Console. Thanks for alerting me to that.

Strange: my error message is "ScriptDiv is not defined."

Your code works great in IE, HTML-Kit and Firefox. I will strive to
adopt that style. In the meantime, I want to follow up with this
innerHTML thing because I think it's used in the routines supporting
Ajax in the Ruby on Rails environment. Now that I know about Error
Console, I'm optimistic I'll get somewhere.
--

 
Reply With Quote
 
RichardL
Guest
Posts: n/a
 
      07-07-2007
On Jul 5, 7:11 am, Dr J R Stockton <(E-Mail Removed)> wrote:
> In comp.lang.javascript message <(E-Mail Removed)
> oglegroups.com>, Wed, 4 Jul 2007 21:03:19, RichardL <RichardDummyMailbox
> (E-Mail Removed)> posted:
>
> >The following script fromhttp://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?

>
> Microsoft code is probably designed, where possible, not to run on other
> systems.
>
> Use, in Firefox, Tools Error Console and it will tell you exactly
> what is first found wrong.
>
> Also, "</SCRIPT" should really be "<\/SCRIPT" .
>
> Don't allow your posting agent to wrap code; read the FAQ.
>
> It's a good idea to read the newsgroup c.l.j and its stale FAQ. See below.
>
> --
> (c) John Stockton, Surrey, UK. ?(E-Mail Removed) Turnpike v6.05 IE 6
> news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
> <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
> <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


> Microsoft code is probably designed, where possible,
> not to run on other systems.


That's sad, if true.

> Use, in Firefox, Tools Error Console

Thanks for that. Lee had mentioned also. I hadn't known about it.

> Also, "</SCRIPT" should really be "<\/SCRIPT" .


Where is that documented. I've been using http://www.w3schools.com/js/js_examples.asp
as a tutorial. They don't escape the forward slash in any of them,
and they seem to run OK in IE7, Firefox 2 and HTML-Kit bld 292.


> Don't allow your posting agent to wrap code; read the FAQ.


I read the FAQ. Do you/they mean end long lines with a \<Enter key> ?
--
R

 
Reply With Quote
 
RichardL
Guest
Posts: n/a
 
      07-07-2007
On Jul 7, 6:02 pm, RichardL
<(E-Mail Removed)> wrote:
> On Jul 5, 7:11 am, Dr J R Stockton <(E-Mail Removed)> wrote:
>
>
>
> > In comp.lang.javascript message <(E-Mail Removed)
> > oglegroups.com>, Wed, 4 Jul 2007 21:03:19, RichardL <RichardDummyMailbox
> > (E-Mail Removed)> posted:

>
> > >The following script fromhttp://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?

>
> > Microsoft code is probably designed, where possible, not to run on other
> > systems.

>
> > Use, in Firefox, Tools Error Console and it will tell you exactly
> > what is first found wrong.

>
> > Also, "</SCRIPT" should really be "<\/SCRIPT" .

>
> > Don't allow your posting agent to wrap code; read the FAQ.

>
> > It's a good idea to read the newsgroup c.l.j and its stale FAQ. See below.

>
> > --
> > (c) John Stockton, Surrey, UK. ?(E-Mail Removed) Turnpike v6.05 IE 6
> > news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
> > <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
> > <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
> > Microsoft code is probably designed, where possible,
> > not to run on other systems.

>
> That's sad, if true.
>
> > Use, in Firefox, Tools Error Console

>
> Thanks for that. Lee had mentioned also. I hadn't known about it.
>
> > Also, "</SCRIPT" should really be "<\/SCRIPT" .

>
> Where is that documented. I've been usinghttp://www.w3schools.com/js/js_examples.asp
> as a tutorial. They don't escape the forward slash in any of them,
> and they seem to run OK in IE7, Firefox 2 and HTML-Kit bld 292.
>
> > Don't allow your posting agent to wrap code; read the FAQ.

>
> I read the FAQ. Do you/they mean end long lines with a \<Enter key> ?
> --
> R


I meant: split long line by inserting "\<Enter key>" after say 30 or
40 characters, and do that recursively?




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSD 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments