<p>In this case it is a frame page that is linking to this document. IE returns the URL of the frame page and Netscape returns the URL of the document linking to this document.</p>
</body> </html>
显示当前文档的标题
<html> <head> <title>MY TITLE</title> </head>
<body> The title of the document is: <script type="text/javascript"> document.write(document.title) </script> </body>
<head> <script type="text/javascript"> function getElement() { var x=document.getElementById("myHeader") alert("I am a " + x.tagName + " element") } </script> </head>
<body> <h1 id="myHeader" onclick="getElement()">Click to see what element I am!</h1> </body>
</html>
显示表单中元素的个数
<html>
<head> <script type="text/javascript"> function getElements() { var x=document.getElementsByName("myInput") alert(x.length + " elements!") } </script> </head> <body>
<form > <input name="myInput" type="text" size="20"><br /> <input name="myInput" type="text" size="20"><br /> <input name="myInput" type="text" size="20"><br /> <br /> <input name="mybutton" type="button" onclick="getElements()" value="Show how many elements named 'myInput'">