【JavaScript】BOOOOOM!
文章目录
有关BOM的详细属性和方法请参阅相关文档,这里只列举常用的属性和方法,不做其他赘述。
window
window表示浏览器的一个实例。它既是通过JavaScript访问浏览器窗口的一个接口,又是ECMAScript规定的global对象。所有在全局作用域声明的变量和函数都会成为window对象的属性和方法。全局变量不能通过delete操作符删除(通过var在全局作用域中定义,其configurable为false),而直接在window对象上定义的属性可以。
frames类数组对象,保存着页面中所有的框架,通过数字索引(从0开始,从上到下,从左到右)访问相应的window对象。top始终指向最外层框架,也就是浏览器窗口。parent指向当前框架的直接上层框架。self始终指向window,实际上,self和window对象可以互相访问。name框架的名称。
window.open()既可以导航到一个特定的URL,也可以打开新的浏览器窗口。
setTimeOut()、clearTimeOut()间歇调用。setInterval()、clearInterval()超时调用。
系统对话框:alert()、confirm()、prompt()
function inputName() {
var areYou = prompt("What't is you name?", "your name");
if (areYou !== null && areYou !== "your name") {
if(confirm("Is your name " + areYou + "?")) {
alert("Your name is " + areYou);
} else {
inputName();
}
} else {
alert("Please input your name again!");
inputName();
}
}
inputName();
location
location提供了与当前窗口中加载的文档有关的信息,还提供了一些导航功能。它既是window对象的属性,也是document对象的属性。也就是说。window.location和document.location引用的是同一对象。
-
查询字符串参数
function getQueryStringArgs() { var qs = (location.search.length > 0) ? location .search.substring(1) : '', //取得查询字符串并去掉开头的问号。location.search获取URL中的查询字符串 args = [], //保存最终数据的数组 items = qs.length ? qs.split('&') : [], //将每一项名值对分隔开保存在items中 item = null, //设置每一项名值对 name = null, //每一项的名 value = null, //每一项的值 len = items.length; for (var i=0; i<len; i++) { item = items[i],split('='); //将每一项名值对的名和值分割开保存在数组中 name = decodeURIComponent(item[0]); //保存名。decodeURIComponent()解码 value = decodeURIComponent(item[1]); //保存值 if (name.length) { args[name] = value; } } return args; } 位置操作
location.href常用来打开新的浏览器位置。location.replace()接受一个URL,跳转到这个位置,但不会再历史记录中生成新的记录。location.reload()如果页面没有改变,从缓存中重新加载,否则从服务器加载。如果为其传递参数true,则强制从服务器重新加载。
navigator
navigator对象多用于检测浏览器类型。
-
检测插件
//检测插件(IE中无效) function hasPlugin(name) { name = name.toLowerCase(); for (var i=0; i<navigator.plugins.length; i++) { if (navigator.plugins[i].name.toLowerCase().indexOf(name) > -1) { return true; } } return false; } //检测IE中的插件 function hasIEPlugin(name) { try { new ActiveXObject(name); return true; } catch(ex) { return false; } } //检测所有浏览器中的Flash插件 function hasFlash() { var result = hasPlugin('Flash'); if (!result) { result = hasIEPlugin('ShockwaveFlash.ShockwaveFlash'); } return result; }
screen
screen对象用来表明客户端的能力,包括浏览器窗口外部的显示器信息。
history
history对象保存着用户上网的历史记录,从窗口被打开的那一刻算起。
history.go()接受要前进或者后退的页面数。正数前进,负数后退。history.back()后退一页,相当于history.go(1)。history.forward()前进一页,相当于history.go(-1)。history.length历史记录的数量。
转载请注明出处:https://segmentfault.com/a/1190000004592551
文章不定期更新完善,如果能对你有一点点启发,我将不胜荣幸。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论