温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

JavaScript中bom是什么

发布时间:2021-06-26 10:05:58 来源:亿速云 阅读:142 作者:小新 栏目:web开发

这篇文章将为大家详细讲解有关JavaScript中bom是什么,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

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>

定时任务

<script type="application/javascript">
function setTime() {
// window.setTimeout("alert('hello!')",5000);
window.setTimeout(sayHello, 5000);
}
var sayHello = function () {
alert("你好!");
}
</script>
</head>
<body>
<button onclick="sayHello();">调用sayHello</button>
<button onclick="setTime();">调用setTime</button>

间隔执行任务

<script type="application/javascript">
/*
window.onload = function(){
window.setTimeout(closeSelf, 1000);
}
function closeSelf() {
var secval = document.getElementById("sec").innerHTML;
var secint = parseInt(secval);
document.getElementById("sec").innerHTML = --secint;
if(secint == 0){
window.close();
}
window.setTimeout(closeSelf, 1000);
}
*/

var taskid = 0;
window.onload = function(){
//间隔执行任务,间隔 1000ms 执行一次
taskid = window.setInterval(closeSelf, 1000);
}
function closeSelf() {
//获取 10s 
var secval = document.getElementById("sec").innerHTML;
console.log(secval);
var secint = parseInt(secval);
console.log(secint);
//10s 减减
document.getElementById("sec").innerHTML = --secint;
if(secint == 0){
window.close();
}
}
// 4.清除间隔执行任务 暂停
function stopTask(){
window.clearInterval(taskid);
}
//继续计时
function goonTask(){
taskid = window.setInterval(closeSelf, 1000);
console.log(taskid)
}
</script>
<body>
付款成功,页面将在<span id="sec">10</span>s后关闭。
<button onclick="stopTask()">稍等,待会我会自己关闭</button>
<button onclick="goonTask()">继续读秒,关闭窗口</button>
</body>

关于“JavaScript中bom是什么”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI