1.在开发过程中我们前端的用户体验中有时候会要求点击一个按钮,关闭当前浏览器窗口。用html DOM就可做到。
2.注意:本次写法要求在新窗口中关闭。 target="_blank"
3. 由a.html 中打开b.html 在b页面中点击按钮关闭B页面
4. a页面代码
1 2 3 4 5 6 7 8 9 10 11 12 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<title> new document </title>
<meta http-equiv= "Content-Type" content= "text/html;charset=UTF-8" />
</head>
<body>
<div>
<a href='button_colse.html' target= "_blank" >测试点击按钮关闭当前页面</a>
</div>
</body>
</html>
|
登录后复制
5. b页面代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<title> new document </title>
<meta http-equiv= "Content-Type" content= "text/html;charset=UTF-8" />
<style type= "text/css" ></style>
<script type= "text/javascript" src= "jquery-1.7.1.min.js" ></script>
</head>
<body>
<div>
点击我关闭本页面
</div>
<button onclick= "javascript:window.opener=null;window.open('','_self');window.close();" type= "button" role= "button" aria-disabled= "false" >
<span class = "ui-button-text" >
<span>关闭</span>
</span>
</button>
</body>
</html>
|
登录后复制
以上是实现在新打开的页面点击关闭窗口的方法的详细内容。更多信息请关注PHP中文网其他相关文章!