1.ECMAscript(核心标准): 定义了基本的语法,比如:if for 数组 字符串 ...
2.BOM : 浏览器对象模型(Browser Object Model)
1.window对象 每一个子窗口对应的又是一个window对象
2. screen对象
3.location对象
4.history对象
5.Navigator对象
6.定时器 (两种)
7.弹框(三种)
8. document (DOM-文档对象模型)
1.1window 对象(表示浏览器窗口):
1.2window 尺寸:
查看window尺寸有三种方式适用于不同的情况:
1) w3c标准(适用于老版本ie之外的浏览器)
2) 老版本的IE浏览器
标准模式:
document.documentElement.clientHeight)
document.documentElement.clientWidth)
怪异模式(向后兼容)中:
document.body.clientHeight
document.body.clientWidth
3)如何知道是何种模式?
console.log(document.compatMode)可以查看文档是以什么方式进行解析的
CSS1Compat 标准模式
BackCompat 怪异模式
function getScreen(){ //获取屏幕的可视宽高
if (window.innerWidth) { //如果window底下有这个属性,就用这个, w3c标准
return {
width : window.innerWidth,
height : window.innerHeight
}
}else{ //老版本IE
if(document.compatMode == "CSS1Compat"){ //标准模式
return {
width : document.documentElement.clientWidth,
height : document.documentElement.clientHeight
}
}else{ //怪异模式
return {
width : document.body.clientWidth,
height : document.body.clientHeight
}
}
}
}
console.log(getScreen())
1.3 其他 Window 方法
•window.open() - 打开新窗口
•window.close() - 关闭当前窗口
•window.moveTo() - 移动当前窗口
•window.resizeTo() - 调整当前窗口的尺寸
2.1 screen 对象(包含有关用户屏幕的信息)
<script>
document.write("可用宽度:" + screen.availWidth);
document.write("可用高度:" + screen.availHeight);
</script>
console.log(location.href) //返回(当前页面的)整个 URL: console.log(location.hash) //hash 哈希值,也叫锚点,比方说a链接中的 console.log(location.host) // host 设置或返回主机名和当前 URL 的端口号。 console.log(location.hostname) // hostname 设置或返回当前 URL 的主机名。 console.log(location.pathname) // pathname 设置或返回当前 URL 的路径部分。 console.log(location.port) // port 设置或返回当前 URL 的端口号。 console.log(location.protocol) // protocol 设置或返回当前 URL 的协议。 console.log(location.search) // search 参数(查询字符串) 设置或返回从问号 (?) 开始的 URL(查询部分)。 // location.href = "http://www.baidu.com" //放到某一个事件中去触发
4.1 history对象(包含浏览器的历史记录)
<body>
<a href="http://www.baidu.com">去百度</a>
<button>后退</button>
<button>前进</button>
<script>
var btn1 = document.getElementsByTagName("button")[0];
var btn2 = document.getElementsByTagName("button")[1];
btn1.onclick = function(){
history.back()
}
btn2.onclick = function(){
history.forward()
}
</script>
</body>
5.1 Navigator对象(记录了浏览器的一些信息的对象)
<div id="example"></div>
<script>
txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";
txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>";
document.getElementById("example").innerHTML=txt;
</script>
6.1 PopupAlert 对象
警告框:alert("文本")
确认框:confirm("文本")
提示框:prompt("文本","默认值")
7.1 Timing 对象
一次性定时器:
setTimeout() 未来的某时执行代码;
clearTimeout() 取消setTimeout();
无限次定时器:
setInterval( );
clearInterval();
8.1 cookie (用来识别用户)
有关cookie的例子:
名字 cookie:
当访问者首次访问页面时,他或她也许会填写他/她们的名字。名字会存储于 cookie 中。当访问者再次访问网站时,他们会收到类似 "Welcome John Doe!" 的欢迎词。而名字则是从 cookie 中取回的。
密码 cookie:
当访问者首次访问页面时,他或她也许会填写他/她们的密码。密码也可被存储于 cookie 中。当他们再次访问网站时,密码就会从 cookie 中取回。
日期 cookie:
当访问者首次访问你的网站时,当前的日期可存储于 cookie 中。当他们再次访问网站时,他们会收到类似这样的一条消息:"Your last visit was on Tuesday August 11, 2005!"。日期也是从 cookie 中取回的。
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务