Web基础 ( 五 ) JavaScript BOM

4.4.BOM浏览器对象模型

window代表窗体, 内置多种对象, 每种对象包含多种方法及属性

4.4.1.location 地址栏

window.location.href = "url";  // 当前窗口加载指定的页面

location.reload(); //刷新

4.4.2.history 访问历史记录

window.history.back();  // 返回上一页面

window.history.forward();  // 前进到下一页面

window.history.go(-1);  // 向前或者向后跳转几个页面

window.history.length;  // 总访问数

在这里插入图片描述

4.4.3.时间处理

4.4.3.1.延时效果:
ident=window.setTimeout("alert('延时弹出')",1000);

window.clearTimeout(ident); // 取消延时效果
4.4.3.2.定时效果:
iv=window.setInterval("console.log('定时弹出')",1000);

window.clearInterval(iv); // 取消定时效果

4.4.4.对话窗口

4.4.4.1.警告(提示)窗
window.alert("提示内容");  // 警告提示窗

在这里插入图片描述

4.4.4.2.确认窗
window.confirm("你确定吗?");  // 确认窗口

在这里插入图片描述

4.4.4.3.输入窗
 window.prompt("请输入"); // 输入窗口

在这里插入图片描述

以上三种窗口弹出时, 程序暂停进行

4.4.4.4.控制台 console

​ 控制台输出 console.log(); console.info() console.error()

在这里插入图片描述

注意: 是浏览器的控制台, 打开”开发者工具”才能看到

4.4.4.5.在窗体中生成HTML元素
document.write("<input>")

4.4.5.窗体

4.4.5.1.弹出页面 open
op = window.open("open1.html"); // 弹出窗体
4.4.5.2.框架页
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
</head>
<frameset  rows="80,*">
	<frame  src="top.html" name="top"/>
	<frameset  cols="180,*">
		<frame src="left.html" name="left"  />
		<frame src="right.html"  name="right"/>
	</frameset>
</frameset>
</html>
4.4.5.3.iframe 内嵌页
<iframe name="标识" src="页面路径" width="" height=""></iframe>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<span>这是一个iframe页面</span>
		<iframe src="child.html" frameborder="1"></iframe>
	</body>
</html>
4.4.5.4.父窗口 操作 子窗口

通过 iframename 属性 得到 子窗口

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<span>这是一个iframe页面</span> 
		<button type="button" onclick="fn()">load iframe</button>
		<iframe name="ifr"  frameborder="1"></iframe>
	</body>
	<script>
		function fn(){
			ifr.location.href="child.html"
		}
	</script>
</html>
4.4.5.5.子窗口 操作 父窗口

在 子窗口中 通过 parent 得到 父窗口

父窗口 main.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<span>这是一个iframe页面</span> 
		
		<button type="button" onclick="fn()">load iframe</button>
		<iframe name="ifr" src="child.html" frameborder="1"></iframe>
	</body>
	<script>
	
		function ff(){
			console.log("这是父窗口")
		}
	</script>
</html>

子窗口 child.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<button type="button" onclick="fn()" >按钮</button>
	</body>
	<script>
		function fn(){
			parent.ff();
		}
	</script>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值