本节主要讲解JavaScript中的Windows对象,浏览器本身常用对象的使用,BOM。
一、浏览器本身自己就有一些对象,不用创建就可以使用
wondow :代表当前流量器窗体的
属性:status 状态栏
opener 在子窗体中代表父窗体的对象
closed
parent
top
方法:
alert()
confirm()
setInterval()//页面动的东西
clearInterval()
setTimeout() //只执行一次
clearTimeout()
open() //打开一个新窗体的是与原窗体有关系的
window包括子对象document ; event; frames//分帧 ; location
[window].成员:window可以省略 只有window可以省略
例1
<a href="del.php" οnclick="return confirm('你确定要删除吗?')">删除</a>
例2
<div id="one" style="position:absolute:left:0; top:0;width:100px;height:100px;">我是广告</div>
<script>
var x=0;
var y=0;
var xs=10;
var ys=10;
var one=document.getElementById("one");
function move(){
x+=xs;
y+=ys;
if(x>=document.body.clientWidth-one.offsetWidth-20 ||x<=0){
xs=-1*xs;
}
if(y>=document.body.clientHeight-one.offsetHeight-20 ||y<=0){
ys=-1*ys;
}
one.style.left=x;
one.style.top=y;
}
var dt=setInterval("move()",100);
one.οnmοuseοver=function(){
clearInterval(dt);
}
one.οnmοuseοut=function(){
dt=setInterVal("move()",100);
}
</script>
例3
<body>
<script>
setTimeout(function(){
document.bgColor="red";
},3000;)
setTimeout(function(){
document.bgColor="blue";
},6000);
setTimeout(function(){
document.bgColor="green";
},9000);
function stop(){
clearTimeout(two);
}
</script>
<input type="button" οnclick="stop()" value="add">
</body>
例4//也是打开一个新窗体 但是open()方法是与父窗体是有联系的。而这个是无联系的
<body>
<a href="1.html" target="_blank">新</a>
</body>
window对象(下)
window.open("url","windowName","windowFeature")
例1 //在父窗体中操作子窗体
<body οnunlοad="closeit()">
<script>
var subwin=window.open("win.html","_blank","top=300,left=300,width=200,height=200,fullscreen=yes");//返回的是子窗体
function show(obj){
subwin.document.bgColor=obj.value;
}
function demo(){
window.document.title="qqqqqq";
}
function closeit(){ //如果关闭父窗体那么子窗体也跟着关闭了
if(subwin.closed){
subwin.close();
}
}
</script>
<input type="button" οnclick="show(this)" value="red"><br>
<input type="button" οnclick="show(this)" value="green"><br>
<input type="button" οnclick="show(this)" value="yello"><br>
<input type="button" οnclick="show(this)" value="blue"><br>
<input type="button" οnclick="show(this)" value="#ff00ff"><br>
</body>
例2//在子窗体总操作父窗体
在win.html中写
<body>
<script>
opener.demo();//子窗体调用父窗体里的方法
function show(obj){
opener.document.bgColor=obj.value;
}
</script>
<input type="button" οnclick="show(this)" value="red"><br>
<input type="button" οnclick="show(this)" value="green"><br>
<input type="button" οnclick="show(this)" value="yello"><br>
<input type="button" οnclick="show(this)" value="blue"><br>
<input type="button" οnclick="show(this)" value="#ff00ff"><br>
</body>
例3//让本身的窗体慢慢变大 然后过5秒关闭
<body>
<script>
opener.demo();
function show(obj){
opener.document.bgColor=obj.value;
}
setInterval(function(){
window.resizeBy(5,5);//相对变大
},100);
setTimeout(function(){
window.close();
},5000)
</script>
<input type="button" οnclick="show(this)" value="red"><br>
<input type="button" οnclick="show(this)" value="green"><br>
<input type="button" οnclick="show(this)" value="yello"><br>
<input type="button" οnclick="show(this)" value="blue"><br>
<input type="button" οnclick="show(this)" value="#ff00ff"><br>
</body>
例4
<body οnunlοad="closeit()">
<script>
var subwin=window.open("win.html","_blank","top=300,left=300,width=200,height=200,fullscreen=yes");//返回的是子窗体
function show(obj){
subwin.document.bgColor=obj.value;
}
function demo(){
window.document.title="qqqqqq";
}
function closeit(){ //如果关闭父窗体那么子窗体也跟着关闭了
if(subwin.closed){
subwin.close();
}
}
var num=0;
var dir=1;
setInterval(function(){
if(num>40||num<0){
dir=-1*dir
}
num+=dir;
var space=""
for(var i=0;i<num;i++){
space+="";
}
window.status=space+"www.borther.com";
},100)
</script>
<input type="button" οnclick="show(this)" value="red"><br>
<input type="button" οnclick="show(this)" value="green"><br>
<input type="button" οnclick="show(this)" value="yello"><br>
<input type="button" οnclick="show(this)" value="blue"><br>
<input type="button" οnclick="show(this)" value="#ff00ff"><br>
</body>
document
frames
location
history
screen
例5
<frameset rows="100,*">
<frame name="top">
<frameset cols="150,*">
<frame name="menu" src="menu.html"/>
<frame name="main"/>
</frameset>
</frame>
</frameset>
menu.html
<input type="button" οnclick="window.document.bgColor='yellow'" value="改自己的"><br>
<input type="button" οnclick="window.parent.parent.frames[0].document.bgColor='green'" value="改上面的"><br>
<input type="button" οnclick="window.top.frames.['main'].document.bgColor='blue'" value="改右面的"><br>
知识小结
[window.]成员
document.write();
本身window
open可以弹出子窗体
frames多个窗体