document对象包含一些属性,如:domain,referrer。
下面代码遍历了document中包含的所有对象,另外,打开一个新的窗口,在新的窗口中用document对象的open方法,打开新的文档,在文档里输入了标签,最后用close方法关闭文档。
通过document.getElementById document.getElementsByName可以找到指定id或者属性名称的标签。
代码:
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE id="title1"> New Document </TITLE>
<META CHARSET="gb2312">
<script language="javascript">
function openWinDoc()
{
myWin = window.open("","","width=500,height=500");
myWin.document.open("text/html","replace");
myWin.document.write("<html><head><title>新文档</title></head>");
myWin.document.write("<body>这是一个新的文档</body></html>");
myWin.document.close();
}
function getId()
{
var c = document.getElementById("title1").tagName;
alert("窗口标题:" + c);
}
function getName()
{
var c = document.getElementsByName("blist").length;
alert("按钮个数:" + c);
}
</script>
</HEAD>
<BODY>
<input type="button" value="打开新窗口-文档" οnclick="openWinDoc()"><br><hr>
<input type="button" name="blist" value="用id获取窗口标题的标签" οnclick="getId()"><br><hr>
<input type="button" name="blist" value="用name获取button属性名为blist的按钮数量" οnclick="getName()"><br><hr>
<script language="javascript">
/*
domain: 服务器的网域名
referrer: 连接这个网页的url
title: 标题
url:网页url
*/
for(o in window.document)
if(typeof(window.document[o]) != "unknown" )
window.document.write(o + ":->" + window.document[o] + "<br>");
else
window.document.write(o + ":-><br>");
</script>
</BODY>
</HTML>