js的bom对象简介

bom:全称为:browser object model 浏览器对象模型
那具体有哪些对象呢?

1.navigator 可以获取客户机的信息(获取浏览器的信息)。比如浏览器的类型。

document.write(navigator.appName);

2.screen 获取屏幕的一些信息,例如分辨率。

 document.write(screen.width);
 document.write(screen.height); 

3.location获取到请求的url地址,并且可以设置url的地址,例如在页面上放置一个按钮,按钮上绑定一个事件,当我点击这个按钮时,页面可以跳转到另外一个页面。

document.write(location.href);//获取当前的文件路径
<input type="button" value="tiaozhuan" onclick="href1();"/>
function href1(){
location.href="a.html";
}

4.history 请求url的历史记录。

 <input type="button" value="back" onclick="back1();"/>
 <input type="button" value="next" onclick="next1();"/>
 <script type="text/javascript">
 //到上一个页面
 function back1(){
     history.back();
 }
 //到下一个页面
 function next1(){
     history.forward();
 }

5.Window 窗口对象,js的顶层对象(所有的bom对象都是在window里面操作的)。
主要有以下几个方法:(都很重要)
window.alert();页面弹出一个框,显示内容
window.confirm();表示确认框
prompt();输入的对话框
open (”打开新窗口的地址URL”,”窗口特征比如宽度高度”);打开一个新的窗口。创建按钮,点击 这个按钮,打开一个新的窗口。
window.open(“06js.html”,”“,”width=100,height=200”);
close();关闭窗口,浏览器兼容性要差一点
setInterval(“js代码”,”毫秒数”)定时器,按照指定周期循环
window.setInterval(“alert’123’”,2000);
setTimeout()在指定的毫秒数之后来调用
window.setTimeout (“js代码”,”毫秒数”);
clearInterval()清除setInterval定时器
clearTimeout()清除setTimeout
具体的完整代码实现如下:

<html>
 <head>
  <title>HTML示例</title>
  <style type="text/css">

  </style>
 </head>
 <body>
 <input type="button" value="tiaozhuan" onclick="open1();"/>
 <input type="button" value="tiaozhuan" onclick="href1();"/>
  <input type="button" value="tiaozhuan" onclick="clear1();"/>
 <input type="button" value="tiaozhuan" onclick="clear2();"/>

 <script type="text/javascript">
 function href1(){
    location.href="a.html";
 }
 //navigator对象
 document.write(navigator.appName);

 //screen对象
 document.write(screen.width);
 document.write(screen.height); 

 //location
 document.write("<hr/>");

 //history

 //confirm
 var flag=window.confirm("你是猪吗");
 if(flag==true){
     alert("删除成功");
 }
 if(flag==false){
     alert("删除失败");
     }

 alert(flag);

//prompt 输入窗口
window.prompt("pleace input:","0");

//open方法
function open1()
{
    window.open("06js.html","","width=100,height=200");
}

//setInterval
window.setInterval("alert’123’;",2000);

//setTimeout
window.setTimeout("alert’123’;",2000);

//setInterval
function clear1(){
window.setInterval("alert’123’;",2000);}

function clear2(){
//setTimeout
window.setTimeout("alert’123’;",2000);}
 </script>
 </body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值