前言
js入门部分说的是js的语言特性,主要是变量类型和语句的使用,语言基于对象的思想等语言层面的东西。
当js应用于浏览器中时,要想发挥作用,需要与浏览器、html文档的各个部分发生作用,那么如何操作这些浏览器以及html文档的组件呢? A: 方法就是将浏览器和HTML文档各组成部分都看做对象,由W3C制定标准,由浏览器厂商实现各种对象,并提供各种操作接口。
* 将这些由浏览器厂商内置的对象大概分为两类,BOM和DOM
1 浏览器对象模型 (BOM)
BOM browser object model
window对象
常用方法
- alert(message)
- confirm(message) 返回值为true / false
- prompt(message) 返回值为输入值
- setTimeout(func,millisec)
- setInterval(func,millisec)
设置时间间隔与清除
//设置间隔与清除
var i = setInterval();
clearInterval(i);
Location对象
<div id="result"></div>
<script src="http://apps.bdimg.com/libs/zepto/1.1.4/zepto.min.js" type="text/javascript" charset="utf-8"></script>
<script>
$(document).ready(function(){
for(x in location)
$("#result").append("<br>"+x+" : "+location[x]);
});
</script>
/*
访问地址: http://127.0.0.1:8020/testweixin/test.html?name=lilei
结果如下:关键看 protocol, host,hostname,port,pathname,search ==> href
replace : function () { [native code] }
assign : function () { [native code] }
ancestorOrigins : [object DOMStringList]
origin : http://127.0.0.1:8020
hash :
search : ?name=lilei
pathname : /testweixin/test.html
port : 8020
hostname : 127.0.0.1
host : 127.0.0.1:8020
protocol : http:
href : http://127.0.0.1:8020/testweixin/test.html?name=lilei
reload : function reload() { [native code] }
*/
主要方法
* reload 重载该网页
* assign(url) 跳转到新的链接 不共用窗口 可以回退
* replace(url) 跳转到新的链接 共用窗口 擦除原来url的痕迹使用js进行网页跳转有三种方式
* location.href = url
* location.assign(url)
* location.replace(url)
Navigator对象
属性名 | 解释 |
---|---|
appName | 浏览器名称,但为什么我这里不管firefox还是chrome都是现实Netscape呢,难道是为了忘却的纪念 |
userAgent | 这个大概能确定浏览器类型,而且该属性会被加入http请求头部 |
别的 | 好像没什么用,太乱了,厂商设置得太乱了 |
Screen对象
- 注意:这个是显示器(显示屏)的对象 ,不是浏览器窗口
//我的机器的内容如下:
availWidth : 1366
availHeight : 728
width : 1366
height : 768
colorDepth : 24
pixelDepth : 24
availLeft : 0
availTop : 0
2 文档对象模型 HTML Document Object Model
TO BE CONTINUED