1. Window Position
The following gets the position of the browser window from the left and top of the screen
Copy Code code as follows:
var leftpos = (typeof Window.screenleft = "number")? Window.screenLeft:window.screenX; Left position
var toppos = (typeof window.screentop = "number")? Window.screenTop:window.screenY; Top position
2. Browser size
The following gets the size of the viewport on the browser page
Copy Code code as follows:
var pagewidth = window.innerwidth,
PageHeight = Window.innerheight;
if (typeof pagewidth!= "number") {
if (Document.compatmode = = "Css1compat") {
PageWidth = Document.documentElement.clientWidth;
PageHeight = Document.documentElement.clientHeight;
} else {
Pagewith = Document.body.clientWdith;
PageHeight = Document.body.clientHeight;
}
}
3. Open or pop up a window
window.open () method, you can accept 4 parameters, usually just specify the first argument, the first argument is a URL, and the second parameter is _self, _parent, _top, _blank, or frame name
Copy Code code as follows:
window.open ("http://www.baidu.com");
window.open ("http://www.baidu.com", "_blank");
window.open ("http://www.baidu.com", "Topframe", "height=400,width=400,top=10,left=10,resizable = yes");
Topframe.resizeto (500,300); resizing windows
Topframe.moveto (100,100); Move Window Position
Topframe.close (); Close the newly opened window, IE will complain
4.location objects
Location.href (URL) load URL
Copy Code code as follows:
Location.href (URL) load URL
Location.href ("http://www.baidu.com");
Location.href = "http://www.baidu.com"; Ditto
Location.assign = "http://www.baidu.com"; Ditto
Window.loaction = "http://www.baidu.com"; Ditto
Location.replace ("http://www.baidu.com"); Ditto, but cannot be rolled back
Location.reload (); Reload (may be loaded from cache)
Location.reload (TRUE); Reload (load from server)
Location.search () returns the query string in the URL, which the string thinks? Beginning
5. Get query string parameters
Copy Code code as follows:
function Getquerystringargs () {
var qs = (location.search.length > 0) location.search.substring (1): "";
var args ={};
var items = qs.split ("&");
var item = Null,name = Null,value = null;
for (var i=0; i<items.length; i++)
{
Item = itmes[i].split ("=");
Name = decodeURIComponent (item[0]);
Value = decodeURIComponent (item[1]);
Args[name] = value;
}
return args;
}
Suppose the query string parameter is? q=javascript&num=10
var args = Getquerystringargs ();
Alert (args["Q"]); "JavaScript"
Alert (args["num"]); "10"
6.history objects
Copy Code code as follows:
History.go () page jump
History.go (-1); Back one page
History.go (1); Forward one page
History.go (2); Forward two pages
History.go ("baidu.com"); Jump to the nearest baidu.com page
History.back (); Back one page
History.forword (); Forward one page
Detects whether the current page is the first page that a user opens
Copy Code code as follows:
if (History.length = = 0) {
If the first page is open, perform some action
}
7. Page load
Window.onload () to do something after the end of the page load
Copy Code code as follows:
Window.onload = function () {
Perform certain actions
}