该文章来自于网络,感谢网友的无私奉献。。。
我们常用的一些函数都是全局对象window下面的。这里将其梳理一下:
Timers
计时器
setTimeout函数可以把函数作为参数,也可以传递JS代码的字符串
In practice, setTimeout( ) tells the browser to invoke the function when it has finished running the event handlers for any currently pending events and has finished updating the current state of the document.
如果将延迟时间设为0,那么绑定的函数将在文档的其他事件完成并完成更新DOM内容之后执行该函数。
详细内容,建议大家阅读以下这篇文章:
http://www.blueidea.com/tech/web/2009/6951.asp
文中得出的结论如下:
Browser Location and History
浏览器地址和历史
Location对象的href属性记录了浏览器对当前页面的地址。Location对象的toString方法返回的是href属性,所以通常我们直接用Location。
Location对象还包括定义协议、主机名、路径名等等URL不同部分的对应属性
一段解析查询参数的函数:
function
}
function getArgs( ) { var args = new Object( ); var query = location.search.substring(1); // Get query string var pairs = query.split("&"); // Break at ampersand for(var i = 0; i < pairs.length; i++) { var pos = pairs[i].indexOf('='); // Look for "name=value" if (pos == -1) continue; // If not found, skip var argname = pairs[i].substring(0,pos); // Extract the name var value = pairs[i].substring(pos+1); // Extract the value value = decodeURIComponent(value); // Decode it, if needed args[argname] = value; // Store as a property } return args; // Return the object }
尽管Location是一个对象,但是你可以直接将一个URL地址的字符串传递给它,浏览器会载入该URL地址。
Location.replace()会在历史记录中替换当前条目的URL,而不是新建一个条目。
document.location is a synonym for document.URL
In most cases, document.location is the same as location.href.
When there is a server redirect, however, document.location contains the URL as loaded, and location.href contains the URL as originally requested.
document.location和document.URL是一样的。
document.location在打赌属性框和location.href也是一样的。但当经过服务器页面重定向,document.location包含的是重载后的地址,但location.href包含了原来的地址
Window的常用方法
open()
close()
moveTo()
resizeBy()
resizeTo()
focus()
blur()
scrollBy( ) scrolls the document displayed in the window by a specified number of pixels left or right and up or down
scrollTo( ) scrolls the document to an absolute position
offsetLeft and offsetTop properties that specify the X and Y coordinates of the element
scrollIntoView( ) on any HTML element to make that element visible.
focus()和scrollIntoView()方法都可以让浏览器执行滚动。
cluttering up the user's browsing history with script-generated named anchors could be considered a nuisance in some situations.
window.location.replace("#top");
历史对象中过多的锚节点是让人心烦的,要注意脚本的行为。
Error Handling
错误处理
The onerror property of a Window object is special. If you assign a function to this property, the function is invoked whenever a JavaScript error occurs in that window: the function you assign becomes an error handler for the window
Note that you ought to be able to simply define a global function named onerror( )
Three arguments are passed to an error handler when a JavaScript error occurs.
The first is a message describing the error.
The second argument is a string that contains the URL of the document containing the JavaScript code that caused the error.
The third argument is the line number within the document where the error occurred.
If the onerror handler returns TRue, it tells the browser that the handler has handled the error and that no further action is necessary
window.onerror属性可以指定一个函数,那么在JS发生错误时,该函数就会执行。
你也可以直接定义一个onerror()的全局函数。
有三个参数传递给了该函数:
1、错误信息
2、发生错误的文档地址
3、发生错误的代码在文档中的行数
如果该函数返回true,那么就是告诉浏览器去忽略该错误。
Relationships Between Frames
框架之间的关系
Every window also has a parent property, which refers to the Window object in which it is contained. Thus, the first frame within a window might refer to its sibling frame (the second frame within the window) like this:
parent.frames[1]
If a window is a top-level window and not a frame, parent simply refers to the window itself:
parent == self;
window的frames属性包含了所有框架的window对象,每个window对象都有parent属性。parent属性指向其父窗口的window对象。那么第一个框架的窗口如果要指向第二个框架的窗口,就是
parent.frames[1]
检查是否是顶级窗口:
parent == self
Window and Frame Names
窗口和框架名
frame标签的name属性可以当作a和form的target属性,告诉浏览器表格和链接的目标窗口。
Determining browser vendor and version
最后一点是通过window的navigator属性判断浏览器的,这点虽然不被推荐,但是还是有参考价值的:
};