mozilla

Revision 204115 of anchor

  • Revision slug: Talk:JavaScript/Reference/Global_Objects/String/anchor
  • Revision title: anchor
  • Revision id: 204115
  • Created:
  • Creator: Meandmymachine
  • Is current revision? No
  • Comment Problem with the anchor script on pages of mozilla.org

Revision Content

When I tried to use the following script from the pages of Mozilla.org I got an error message from the JavaScript console in Mozilla Firefox saying that msgWindow was not defined.

The following example opens the msgWindow window and creates an anchor for the table of contents:

var myString="Table of Contents"
msgWindow.document.writeln(myString.anchor("contents_anchor"))

The previous example produces the same output as the following HTML:

<A NAME="contents_anchor">Table of Contents</A>


However when I changed the script to the following, I found that the script worked:

<html> <head> <script language = "JavaScript">

var myString="Table of Contents" window.document.writeln(myString.anchor("contents_anchor"))

//The above script produces the same results as the html in the anchor tags //<A NAME="contents_anchor">Table of Contents</A> </script> </head> <body>

</body> </html>

Revision Source

<p>When I tried to use the following script from the pages of Mozilla.org I got an error message from the JavaScript console in Mozilla Firefox saying that msgWindow was not defined. 
</p><p>The following example opens the <code>msgWindow</code> window and creates an anchor for the table of contents:
</p>
<pre>var myString="Table of Contents"
msgWindow.document.writeln(myString.anchor("contents_anchor"))
</pre>
<p>The previous example produces the same output as the following HTML:
</p>
<pre>&lt;A NAME="contents_anchor"&gt;Table of Contents&lt;/A&gt;
</pre>
<p><br>
However when I changed the script to the following, I found that the script worked:
</p><p>&lt;html&gt;
&lt;head&gt;
&lt;script language = "JavaScript"&gt;
</p><p>var myString="Table of Contents"
window.document.writeln(myString.anchor("contents_anchor"))
</p><p>//The above script produces the same results as the html in the anchor tags
//&lt;A NAME="contents_anchor"&gt;Table of Contents&lt;/A&gt;            
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
</p><p>&lt;/body&gt;
&lt;/html&gt;
</p>
Revert to this revision