window
对象不但充当全局作用域,而且表示浏览器窗口。
window.innerWidth//视口宽度 window.innerHeight//视口高度 window.outerWidth//浏览器宽度 window.outerHeight//浏览器高度
location
对象表示当前页面的URL信息
location.href; // 'http://www.example.com:8080/path/index.html?a=1&b=2#TOP' location.protocol; // 'http' location.host; // 'www.example.com' location.port; // '8080' location.pathname; // '/path/index.html' location.search; // '?a=1&b=2' location.hash; // 'TOP' location.assign("https://www.baidu.com/");// 要加载一个新页面 location.reload(); // 刷新页面
document对象表示当前页面, 是DOM树的根节点
cookie 是一些数据, 存储于你电脑上的文本文件中
cookie 以键/值对的形式保存
document.cookie="username=John Doe;expires=Thu, 18 Dec 2043 12:00:00 GMT; path=/";
var x = document.cookie;
document.cookie="username=John Smith; expires=Thu, 18 Dec 2043 12:00:00 GMT; path=/";
document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
screen对象表示屏幕的信息
screen.width; // 屏幕宽度,以像素为单位; screen.height; // 屏幕高度,以像素为单位; screen.colorDepth; // 返回颜色位数,如8、16、24。
navigator对象表示浏览器的信息
navigator.appName; // 浏览器名称; navigator.appVersion; // 浏览器版本; navigator.language; // 浏览器设置的语言; navigator.platform; // 操作系统类型; navigator.userAgent; // 浏览器设定的User-Agent字符串。
包含浏览器的历史
history.back(); // 与在浏览器点击后退按钮相同 history.forward(); // 与在浏览器中点击向前按钮相同
window.alert("sometext");
window.confirm("sometext");
window.prompt("sometext","defaultvalue");
setInterval() 方法
setInterval() 间隔指定的时间(毫秒),不停地执行指定的代码
var myInterval = setInterval(function(){alert("Hello")},3000);
clearInterval() 方法
要使用 clearInterval() 方法, 在创建计时方法时你必须使用全局变量
clearInterval(clearInterval);
setTimeout() 方法
间隔指定的时间,执行一次指定的代码
var myVar = setTimeout(function(){alert("Hello")},3000);
clearTimeout()
要使用clearTimeout() 方法, 你必须在创建超时方法中(setTimeout)使用全局变量:
clearTimeout(myVar);