JavaScript BOM编程

打开和关闭新窗口

...
		input type="button" value="开启新窗口" onclick="window.open('http://www.baidu.com');" />
		<input type="button" value="开启当前窗口" onclick="window.open('http://www.baidu.com','_self');" />
		<input type="button" value="开启新窗口" onclick="window.open('http://www.baidu.com','_blank');" />
		<input type="button" value="开启父窗口" onclick="window.open('http://www.baidu.com','_parent');" />
		<input type="button" value="开启顶级窗口" onclick="window.open('http://www.baidu.com','_top');" />
		
		<input type="button" value="打开窗口" onclick="window.open('close.html')" />
...

close.html

<body>
		<input type="button" value="关闭当前窗口" onclick="window.close();" />
	</body>

弹出消息确认框(提示删除)

...
<script type="test/javascript">
window.onload = function(){
			del = function(){
			 	if(window.confirm("亲,确认删除数据吗?")){
			 	alert("date delete...");
			 	}
			 }
				
				
			}
			</script>
...
<input type="button" value="弹出确认框"  onclick="window.alert('消息框')"/>
		<input type="button" value="弹出消息确认框(删除)" onclick="del()" />
...

histroy对象

需求:点击按钮回到起始页面
起始页面

...
     <body>
		<a href="001-BOM编程.html">跳转页面</a>
		<input type="button" value="go" onclick="window.history.go(1)" />
	</body>
...

跳转页面

...
 		<input type="button"value="back" onclick="window.history.back()" />
		<input type="button"value="back" onclick="window.history.go(-1)"/>
...

location

给地址栏设置url

...
function goBaidu(){
				window.location.href="http://www.baidu.com";
//				window.location = "http://www.baidu.com";
//				
//				document.location.href = "http://www.baidu.com";
//				document.location = "http://www.baidu.com";
			}
...
<input type="button" value="百度" onclick="goBaidu();"/>
发布了82 篇原创文章 · 获赞 6 · 访问量 4468

猜你喜欢

转载自blog.csdn.net/OVO_LQ_Start/article/details/104595659