1. Obtain the position of the browser window following the window position on the left and top of the screen. 1 varleftPos (typeofwindow. screenLeft & quot; number & quot ;)? Window. screenLeft: window. screenX; // left position 2 vartopPos (typeofwin...
1. Window position
The following figure shows the position of the browser window from the left and top of the screen.
1 var leftPos = (typeof window. screenLeft = "number ")? Window. screenLeft: window. screenX; // left position
2 var topPos = (typeof window. screenTop = "number ")? Window. screenTop: window. screenY; // above position
2. browser size
The following figure shows the size of the browser page view.
1 var pageWidth = window. innerWidth,
2 pageHeight = window. innerHeight;
3
4 if (typeof pageWidth! = "Number "){
5 if (document. compatMode = "CSS1Compat "){
6 pageWidth = document.doc umentElement. clientWidth;
7 pageHeight = document.doc umentElement. clientHeight;
8} else {
9 pageWith = document. body. clientWdith;
10 pageHeight = document. body. clientHeight;
11}
12}
3. Open or pop-up window
Window. the open () method can take four parameters. Generally, you only need to specify the first parameter, and the first parameter is URL, the second parameter is _ self, _ parent, _ top, _ blank, or framework name.
1 window. open ("http://www.2cto.com ");
2 window. open ("http://www.2cto.com", "_ blank ");
3 window. open ("http://www.baidu.com", "topFrame", "height = 400, width = 400, top = 10, left = 10, resizable = yes ");
4 topFrame. resizeTo (500,300); // adjust the window size
5 topFrame. moveTo (100,100); // move the window position
6 topFrame. close (); // close the new window. IE will report an error
4. location object
Location. href (URL) Load URL
1 location. href (URL) Load URL
2 location. href ("http://www.2cto.com ");
3 location. href = "http://www.2cto.com"; // same as above
4 location. assign = "http://www.2cto.com"; // same as above
5 window. loaction = "http://www.2cto.com"; // same as above
6 location. replace ("http://www.2cto.com"); // same as above, but cannot roll back
7
8 location. reload (); // reload (may load from the cache)
9 location. reload (true); // reload (load from the server)
10
11 location. search () returns the query string in the URL. What is the string? Start
5. Obtain query string Parameters
1 function getQueryStringArgs (){
2 var qs = (location. search. length> 0) location. search. substring (1 ):"";
3 var args = {};
4 var items = qs. split ("&");
5 var item = null, name = null, value = null;
6 for (var I = 0; I 7 {
8 item = itmes [I]. split ("= ");
9 name = decodeURIComponent (item [0]);
10 value = decodeURIComponent (item [1]);
11 args [name] = value;
12}
13 return args;
14}
15
16 // suppose the query string parameter is? Q = javascript & num = 10
17 var args = getQueryStringArgs ();
18 alert (args ["q"]); // "javascript"
19 alert (args ["num"]); // "10"
6. history Object
1 history. go () page Jump
2 history. go (-1); // return a page
3 history. go (1); // Previous Page
4 history. go (2); // two previous pages
5 history. go ("baidu.com"); jump to the latest baidu.com page
6
7 history. back (); // return a page
8 history. forword (); // Previous Page
Checks whether the current page is the first page opened by the user.
1 if (history. length = 0 ){
2 // if this page is the first page opened by the user
3}
From Sunday walk