JavaScript代码..doc
文本预览下载声明
实例一、对窗口对象的closed属性的解释
html
head
titleWindow对象的closed属性/title
script language=javascript
var winid //用来保存open方法打开的新窗口的引用
function donew(){
var outstr= //用来保存向新窗口写入的标记
outstr+=htmlhead/headbody
outstr+=h1这就是那个打开的新窗口/h1br
outstr+=forminput type=button value=关闭主窗口 onclick=window.opener.close()
//window.opener保存打开该窗口的父对象
outstr+=/form/body/html
winid=window.open(,,width=300,height=300)
winid.document.write(outstr)
}
function doclose(){
if(winid!winid.closed){
//用来确定原窗口是否已经被关闭或是否已经定义
winid.close()
}
}
/script
/head
body
h2这个实例是对window对象的closed属性的学习
其中也包括了open()方法,opener属性.../h2br
form
input type=button value=打开新窗口 onclick=donew()
input type=button value=关闭新窗口 onclick=doclose()
/form
/body
/html
实例二、对窗口对象的scrollBy()-scrollTo()方法的解释
html
head
title/title
/head
frameset name=main cols=20%,80%
frame src=scroll_1.html //该frame中为主控窗口
frame src=scroll_2.html //该frame中只放了一张图片
/frameset
/html
实例:scroll_1.html
关于:上面框架集中的左框架中的网页,主要用来控制右边框架中的窗口的滚动
html
head
title/title
script language=javascript
var tmid //保存时间标示
var x1,y1 //全局变量,用来保存相对移动时的参数
function doby(xx,yy){
var obj=parent.frames[1]
//得到右边窗口对象
obj.scrollBy(xx,yy) //相对滚动右边的窗口
x1=xx //
y1=yy //保存参数到全局变量
tmid=setTimeout(doby(x1,y1),100)
//每隔一段时间执行滚动操作
}
function doto(){
var obj=parent.frames[1]
obj.scrollTo(0,0) //绝对滚动到起点
clearTimeout(tmid) //清除时间
}
/script
/head
body
form name=cz
input type=button value=向上滚动 onclick=doby(0,-5)br
input type=button value=向下滚动 onclick=doby(0,5)br
input type=button value=向左滚动 onclick=doby(-5,0)br
input type=button value=向右滚动 onclick=doby(5,0)br
input type=button value=到最上 onclick=doto()
显示全部