BOM(Browser Objects Model):操做浏览器部分功能的API。javascript
打开窗口:html
window.open(url,target);
参数解释:html5
_blank
、_self
、 _parent
父框架。关闭窗口java
window.close(); <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <!--行间的js中的open() window不能省略--> <button onclick="window.open('https://www.baidu.com/')">百度搜索</button> <button>打开百度</button> <button onclick="window.close()">关闭</button> <button>关闭</button> </body> <script type="text/javascript"> var oBtn = document.getElementsByTagName('button')[1]; var closeBtn = document.getElementsByTagName('button')[3]; oBtn.onclick = function(){ //open('https://www.baidu.com') //打开空白页面 open('about:blank',"_self") } closeBtn.onclick = function(){ if(confirm("是否关闭?")){ close(); } } </script> </html>
window.location
能够简写成location。location至关于浏览器地址栏,能够将url解析成独立的片断。linux
<body> <span>luffy</span> <script> var oSpan = document.getElementsByTagName("span")[0]; oSpan.onclick = function () { location.href = "http://www.baidu.com"; //点击span时,跳转到指定连接 // window.open("http://www.baidu.com"","_blank"); //方式二 跳转 } </script> </body>
window.location.reload(); //全局刷新页面,至关于浏览器导航栏上 刷新按钮
window.navigator 的一些属性能够获取客户端的一些信息。api
userAgent:系统,浏览器)浏览器
platform:浏览器支持的系统,win/mac/linuxsession
console.log(navigator.userAgent); console.log(navigator.platform);
一、后退:框架
二、前进:函数
对浏览器来讲,使用 Web Storage 存储键值对比存储 Cookie 方式更直观,并且容量更大,它包含两种:localStorage 和 sessionStorage sessionStorage(临时存储) :为每个数据源维持一个存储区域,在浏览器打开期间存在,包括页面从新加载 localStorage(长期存储) :与 sessionStorage 同样,可是浏览器关闭后,数据依然会一直存在
sessionStorage 和 localStorage 的用法基本一致,引用类型的值要转换成JSON
let info = { name: 'Lee', age: 20, id: '001' }; sessionStorage.setItem('key', JSON.stringify(info)); localStorage.setItem('key', JSON.stringify(info));
var data1 = JSON.parse(sessionStorage.getItem('key')); var data2 = JSON.parse(localStorage.getItem('key'));
sessionStorage.removeItem('key'); localStorage.removeItem('key');
sessionStorage.clear(); localStorage.clear();
Storage 发生变化(增长、更新、删除)时的 触发,同一个页面发生的改变不会触发,只会监听同一域名下其余页面改变 Storage window.addEventListener('storage', function (e) { console.log('key', e.key); console.log('oldValue', e.oldValue); console.log('newValue', e.newValue); console.log('url', e.url); })