首页 > 语言 > JavaScript > 正文

深入学习JavaScript中的bom

2024-05-06 15:38:53
字体:
来源:转载
供稿:网友

BOM(Broswer Object Model)

凡是 window 的属性和方法,均可以省略“window.”

方法:

框窗

1.警告框

window.alert("msg");

2.确认框

window.confirm("msg");

3.询问框

window.prompt("msg","defaulvalue")

页面

1.打开一个窗口

window.open()

2.在子窗口中使用,表示父窗口的window对象

window.opener

window.opener.fatherSayHello(); 调用父窗口的方法window.opener.a

3.关闭当前窗口

window.close()

window.close(); 关闭当前window.opener.close(); 关闭父窗口

定时任务

1.定时任务

var taskid = window.setTimeout(function,ms);window.setTimeout("alert('hello!')", 5000);

2.间隔执行任务

var taskid = window.setInteval(function,ms);

3.清除定时任务

window.clearTimeout(taskid);

4.清除间隔执行任务

window.clearInteval(taskid);

打印屏幕

//长*宽console.log(screen.width + "*" + screen.height)

后退

window.history.back();

前进

window.history.forward();

刷新

window.location.reload();//刷新window.location.href = window.location.href;//刷新

Go 前进(x)步,后退(x)步,刷新(0),

window.history.go(x)

链接

window.location.href = http://www.baidu.com;

用户代理 浏览器内核

console.log(window.navigator.userAgent)

框窗

//凡是window的属性和方法,均可以省略“window.”<script type="application/javascript">// 警告框function testAlert(){var result=window.alert("这是一个警告框")console.log(result);}// confirm 确认框function testConfirm(){var result =window.confirm("你确认要离开了吗?");if(result){alert("欢迎下次再来!")}else{alert("那你在逛逛吧!")}consol.log(result);}// prompt 询问框function testPrompt(){var result = window.prompt("请输入U盾密码","例如:123456");console.log(result);}</script><body><button onclick="testAlert();">testAlert</button><button onclick="testConfirm();">testConfirm</button><button onclick="testPrompt();">testPrompt</button></body>

页面

//子页面<script type="application/javascript">function sayHello(){alert("hello world")}//打开一个窗口function callFatherMethod(){window.opener.fatherSayHello();window.opener.a}//关闭本窗口function testClose(){window.close();}//关闭父窗口function testFatherClose(){window.opener.close();}</script><body><button onclick="callFatherMethod()">调用父窗口的方法</button><button onclick="testClose()">关闭本窗口</button><button onclick="testFatherClose()">关闭父窗口</button></body>//父页面<script type="application/javascript">var a = 10;window.onload = function(){console.log(window);console.log("11111111111")}//打开一个新窗口function testOpen(){var sonwindow = window.open("son.html","aaa","height=300,width=500,top=50,left=50,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no")//子窗口的window对象console.log(sonwindow);}function fatherSayHello(){alert("hello son!");}</script><body><button onclick="testOpen();">打开一个新窗口</button></body>            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选