window对象

计时器


setTimeout : 指定时间之后单次调用

clearTimeout:取消后续函数调用

setInterval:指定之间后重复调用

clearnterval:

单位:毫秒

Location


window 的location属性引用Location对象

window.location === document.location

Location对象属性:

protocol

host

hostname

port

pathname

search

hash

有用方法:

assign:载入指定文档

replace:类似assign

reload

location = '#top',   跳到文档顶部

location.search ="?name = wish"  载入下一个页面

注意:Location对象的url分解属性是可写的,如上面最后语句中修改search载入下一个页面

History


window history属性引用窗口的history对象

history.back()

history.forward()

history.go(-2)

注意: 如果窗口包含多个子窗口,那么子窗口的浏览记录会按时间顺序穿插在主窗口的历史中

 

 Navigator和Screen


navigator属性包含浏览器厂商和版本信息

appName

appVersion

userAgent

platform

screen: 窗口显示的大小和可用颜色数量的信息

对话框


alert()

prompt()

confirm()

showModalDialog()

eg:

var name = prompt("Enter your name");

if(confirm("your name is "+ name));

showModelDialog 见:http://www.cnblogs.com/wishyouhappy/p/3663562.html

注意:1、confirm()和prompt()都会产生阻塞,如果当前正在载入文档,也会停止载入,知道用户用要求的输入进行响应

   2、在大多数浏览器中alert()方法会产生阻塞,并等待用户关闭对话框

   3、应尽量节制使用,用户体谅不好

 

 onError


javascript的早期的遗物,在还没有try/catch时,现代代码很少使用,当然,开发初期可以使用

 

 多窗口和多窗体


每一个标签页都有独立的浏览上下文,每一个上下文都有独立的window对象,相互之间不干扰

打开和关闭窗体:

window.open
window.close

target:

_parent 直接父级窗口

_top: 顶级祖先窗口

_blank

窗体关系:

parent :父窗体

self:自身

top: 包含它的顶级窗口

frame:

方式一:

<iframe id="if1">

var iframeElement = document.getElementById("if1");
var win= iframeElement .contentWindow;  //contentWindow引用该窗体的window对象


方式二:

frames[0];
frames[1].frames[2]; //每个Window对象都有一个frames属性,它引用自身包含的窗体或者窗体的子窗体的引用
frames["if1"];
frames.if1;

窗体交互:

例如:

在一个web页面中有两个iframe A、B

在A中定义变量var i=3; 在B中可以通过 parent.A.i 访问A中的变量 i

原文地址:https://www.cnblogs.com/wishyouhappy/p/3772591.html