open_close
- open():打开网页,类似a标签,行间调用open方法window不能省略,参数2,_self表示当前窗口
- close():关闭当前网页
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>BOM之open方法</title> </head> <body> <button onclick="window.open('https://www.jd.com')">打开</button> <button>打开百度</button> <button>关闭当前页面</button> </body> <script type="text/javascript"> var btn=document.getElementsByTagName('button')[1]; btn.onclick=function () { open("https://www.baidu.com"); //在当前窗口打开空白页面 open('about:blank'); //关闭当前页面 close() } var btn2=document.getElementsByTagName('button')[2]; //经确认后再关闭 btn2.onclick=function () { if(confirm("确认关闭?")){ close() } } </script> </html>