1. Window position
The following is the position of the browser window from the left and top of the screen
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
below to get the size of the browser page viewport
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 window
The window.open() method can accept 4 parameters. Usually you only need to specify the first parameter. The first parameter is the URL, and the second parameter is _self, _parent, _top, _blank or the frame name
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); //Adjust the window size
topFrame.moveTo(100,100); //Move Window position
topFrame.close(); //Close the newly opened window, IE will report an error
4.location object
location.href(URL) Load URL
location.href(URL) Load URL
location.href(" http://www.baidu.com");
location.href = "http://www.baidu.com" ; //Same as above
location.assign = "http://www.baidu. com"; //Same as above
window.loaction = "http://www.baidu.com"; //Same as above
location.replace("http://www.baidu.com"); // Same as above, but cannot go back
location.reload(); //Reload (maybe loaded from cache)
location.reload(true); //Reload (loaded from server)
location.search() returns the query string in the URL. What does the string mean? Beginning with
5. Get the query string parameters
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{
item = itmes[i].split("=");
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
args[name] = value;
}
return args;
}
//Assume the query string parameter is?q=javascript&num=10
var args = getQueryStringArgs();
alert(args["q"]); //"javascript"
alert(args["num"]); //"10"
6.history object
history.go() page jump
history.go(- 1); //Go back one page
history.go(1); //Go one page forward
history.go(2); //Go two pages forward
history.go("baidu.com" ); Jump to the nearest baidu.com page
history.back(); //Back one page
history.forword(); //Forward one page
Detect whether the current page is the first page opened by the user
if (history.length == 0) {
//If the first page is opened, perform certain operations
}
7. Page loading
window.onload() is used to perform certain operations after the page is loaded
window.onload = function () {
//Perform some operations
}