window 对象

提示框 alert

  1. alert(1);

确认提示框 confirm

  1. var conf = confirm('是否打开'); // true

定时器 setTimeout

  1. var t1 = setTimeout(function () {
  2. console.log(1);
  3. }, 1000);

取消定时器 clearTimeout

  1. clearTimeout(t1);

循环定时器 setInterval

  1. var t1 = setInterval(function () {
  2. console.log(1);
  3. }, 1000);

取消循环定时器 clearInterval

clearInterval(t1);

本地化存储 localStorage

// 设置缓存
localStorage.setItem('name', 'xiaoming');

// 读取缓存
localStorage.getItem('name'); // 'xiaoming'

// 删除缓存
localStorage.removeItem('name');

location 对象

获取url地址 location.href

var str = location.href; // 'https://echarts.noxussj.top/#/'

获取域名 location.host

var str = location.host; // 'echarts.noxussj.top'

获取端口号 location.port

var str = location.port; // 8888

获取web协议 location.portocol

var str = location.portocol;

navigator 对象

获取浏览器名称 navigator.appName

var str = navigator.appName; // 'Netscape'

获取浏览器版本 navigator.appVersion

var str = navigator.appVersion; // '5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'

获取操作系统 navigator.platform

var str = navigator.platform; // 'Win32'

history 对象

返回上一页 history.back

history.back();

返回下一页 history.forward

history.forward()

返回上下页 history.go

history.go(-1)

screen 对象

屏幕宽度 screen.width

var str = screen.width; // 1920

屏幕高度 screen.height

var str = screen.height; // 1080

document 对象

浏览器缓存 document.cookie

// 设置cookie
document.cookie = 'name=xiaoming;';

// 访问cookie
var str = document.cookie; //  'name=xiaoming';

// 删除cookie
document.cookie = '';

文档标题 document.title

document.title = 'my-title';

打印内容 document.write

document.write('我是内容');