Revision 204116 of anchor

  • Revision slug: Talk:JavaScript/Reference/Global_Objects/String/anchor
  • Revision title: anchor
  • Revision id: 204116
  • Created:
  • Creator: Maian
  • Is current revision? No
  • Comment

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>

--Meandmymachine 21:12, 13 November 2005

msgWindow should be a var holding a reference to a popup window. I don't know why the example doesn't just use document.writeln. All examples in this reference that use the DOM should minimize usage of the DOM to only basic things like alert, document.write, document.writeln, and innerHTML. I'll change it. --Maian 18:53, 13 November 2005 (PST)

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>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;script language = "JavaScript"&gt;

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
//&lt;A NAME="contents_anchor"&gt;Table of Contents&lt;/A&gt;            
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>--<a href="User:Meandmymachine">Meandmymachine</a> 21:12, 13 November 2005
</p>
<dl><dd> <code>msgWindow</code> should be a var holding a reference to a popup window. I don't know why the example doesn't just use <code>document.writeln</code>. All examples in this reference that use the DOM should minimize usage of the DOM to only basic things like <code>alert</code>, <code>document.write</code>, <code>document.writeln</code>, and <code>innerHTML</code>. I'll change it. --<a href="User:Maian">Maian</a> 18:53, 13 November 2005 (PST)
</dd></dl>
Revert to this revision