!!! JavaScript 是一个单线程序的解释器 !!!
1. window 对象是一个全局对象
2. 所有的页面有三个属性
self: 当前页面上下文
parent: 父级页面上下文
top: 最外层页面上下文
3. window 对象的一些方法
window.close();//关闭当前页面
setTimeout() && clearTimeout();//超时调用
setInterval() && clearInterval();//间歇调用
window.alert();//消息弹出框
window.confirm();//确认弹出框
window.prompt();//弹出输入框
window.print();//打印对话框
4. location对象(location是一个特殊的对象,它同时也是window对象的一个属性)
1. location 对象的所有属性 (修改location 的属性(hash值除外),都会以新的URL重新加载页面)
location.hash;//location 的 hash值
location.host;//主机名 + 端口地址
location.hostname;//主机名
location.href;//浏览器的链接地址
location.pathname;//URL中的目录和文件名
location.port;//端口号
location.protocol;//当前页面使用的协议
location.search;//URL中问号后面的参数
2. location 对象的方法
1) location.assign("http://www.baidu.com");//跳转页面
说明: 在window.location 和 location.href 设置一个URL值时,会直接调用 location.assign();
2)location.reload();//重新加载当前页面,设置参数true时,强制浏览器从服务器重新加载
3. 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) > 0){
return true;
}
}
return false;
}
console.log(hasPlugin("Flash"));//若浏览器中有Flash插件,返回True
//检测 IE浏览器 中的插件
function hasIEPlugin(name){//name 为插件的 com标识符
try{
new ActiveXObject(name);
return true;
}catch(ex){
return false;
}
}
4. Screen 对象(屏幕)
......
5. History对象(历史)
history.forward();//前进
history.back();//返回上一个页面
history.go();//参数可以为URL,数字。 当数字为负数时,向后跳转,正数向前跳转