<p>The referrer of a document is the URL of the document that linked to a document.</p>
The referrer of this document is: <script type="text/javascript"> document.write(document.referrer) </script>
<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'"> </form> </body>
<body> <form> <input type="button" onclick="docOpen()" value="Open a new document"> </form> </body>
</html>
打开一个新的文档,并显示新的文档
<html> <head> <script> function replace() { var newDoc=document.open("text/html","replace") var txt="<html><body>FUN!!!!</body></html>" newDoc.write(txt)