##Special window
Mention window, on the web page It is very common, such as this:window.onload=function(){ //执行函数体 }
JavaScript Video Tutorial]
Because of this, all variables and functions declared in the global scope will become properties and methods of the window object. For example:var age = 29; function sayAge(){ alert(this.age); } alert(window.age); //29 sayAge(); //29 window.sayAge(); //29
Historical legacy
location object
Basic attributes
Location is one of the most useful BOM objects. It provides information and navigation functions for the document loaded in the current window. Its main uses are related to URLs: ●Hash: Returns the characters after the # symbol in the URL, if not, returns empty. ● host/hostname: Returns the server name or port number. ● href: Returns the complete url ● Port: Returns the specified port number ● Protocol: Returns the protocol used Search: Returns the url Query string, that is, everything from the beginning to the end of the question markLocation operation
Location can change the location of the browser in many ways, the most commonly used is assign () method, for example:location.assign("http://www.baidu.com");
window.location = "http://www.baidu.com"; location.href = "http://www.baidu.com";
location.replace("http://www.baidu.com");
location.reload(true);
history object
history Keeps records of users surfing the Internet. Each browser window and tab has its own history object associated with a specific window object. For security reasons, developers generally cannot know which web pages the user has browsed, but there are still The way to implement the forward and backward functions is go(). For example:history.go(-1); history.go(1);
history.go("baidu.com");
if(history.length == 0){ //干你想干的事 }
Summary
The status of the window object in the mobile Internet wave is no longer as important as that of the PC side, and it involves more functions and detection In one aspect, more interactions are involved, while other aspects are implemented by custom code with richer functions. Despite this, the window object is not just that simple. There is also an important navigator object, but when it comes to it, there is a lot of content. I will share it with you in a separate article later. This article comes from thejs tutorial column, welcome to learn!
The above is the detailed content of The role of the Window object in the front-end field. For more information, please follow other related articles on the PHP Chinese website!