document 对象
document 对象是window 对象的属性。从BOM的角度看document 对象是由一系列集合构成。
1、title属性是可读写的,所以随时改变页面的标题
top.document.title = "******"
2、url属性是可读写的,用它可以获取当前页的url ,也可用它设置新的url,进行跳转。
document.url = "http://www.hao123.com"
3、document集合
一、anchors 页面中的所有緢的集合
二、applets 页面中的所有applet集合
三、embeds 页面中的所有嵌入式对象的集合
四、forms 页面中的所有表单的集合
五、images 页面中的所有图像的集合
六、links 页面中的所有链接的集合
* 与window.frame集合相似,可以用数字或者是名字引用document集合的每个对象。用document.images[0]或document.images["image_name"]访问对象。
4、document的方法
一、write() 方法或者 writeln()方法
用此方法可以将字符穿的内容写到调用他们的位置。
<BODY>
<h1><script type = "text/javascript">document.write ("this is a test")</script></h1>
</BODY>
也可用这种方法引入外部的js 文件
但是在引入外部文件时,“</script>”一定要被分成两部分
"</scr"和"ipt>",这是十分必要的。
二、open() 和 close()
open() 方法用于打开已经载入的文档进行编写,close()方法 用于关闭open()方法打开的文档。通常是用这些方法结合起来
向框架或者新打开的窗口写入内容。
var oNewWin = window.open("about:blank","newwindow"
"height=150,width=200,top=10,left=10,resizeable=yes")
oNewWin.document.open()
oNewWin.document.write("<html><head><title>New window</title></head></html>")
oNewWin.document.write("<body>ddddd</body>")
oNewWin.close()