The 1.window object is to relate the browser to JavaScript.
2. The global variable (var a) is the property of the Window object, and the global function (Var a={}) is the method of the Window object.
3.window.document.getelementbyid ("header"); Is the method of the Window object.
4. Get the browser window size
For Internet Explorer, Chrome, Firefox, Opera, and Safari:
- Window.innerheight-Interior height of the browser window
- Window.innerwidth-Interior width of the browser window
For Internet Explorer 8, 7, 6, 5:
- Document.documentElement.clientHeight
- Document.documentElement.clientWidth
Or
- Document.body.clientHeight
- Document.body.clientWidth
5.Window screen to get width and height
- Screen.availwidth-Available screen widths
- Screen.availheight-The available screen height
Note: Remove the width and height of the window's taskbar
The 6.JavaScript Window Location object is used to obtain the address (URL) of the current page and redirect the browser to a new page
- Location.hostname returns the domain name of the web host
- Location.pathname returns the path and file name of the current page
- Location.port returns the port of the web host (80 or 443)
- Location.protocol returns the Web protocol used (HTTP///https://)
7.JavaScript Window History
- Window.history.back ()-Same as clicking Back button in browser
- Window.history.forward ()-Same as clicking the button in the browser forward
8.JavaScript message box
Warning Box: Confirm alert ("text")
Confirm Box: Confirm + Cancel Confirm ("text"), "confirm" return value is true; "Cancel" return value is False
Prompt box: Confirm + Cancel Prompt ("text", "Default value"), "confirm" return value is input value; "Cancel" return value is null
9.JavaScript Chronograph
-
-
SetTimeout ()
-
-
future execution of code at some time
-
-
Cleartimeout ()
-
-
Cancel settimeout ()
-
-
-
setTimeout () syntax: Var t=settimeout ("javascript statement", MS)
-
-
-
Example: Infinite loop timer
-
<HTML><Head><Scripttype= "Text/javascript">varC=0varTfunctionTimedcount () {document.getElementById ('txt'). Value=C c=C+1T=SetTimeout ("Timedcount ()", +) }</Script></Head><Body><form><inputtype= "button"value= "Start count!"OnClick= "Timedcount ()"><inputtype= "text"ID= "txt"></form></Body></HTML>
Cleartimeout () Syntax: cleartimeout (settimeout_variable)
Example: In the example above, add the following function to stop the timer.
function Stopcount () {cleartimeout (t)}
Javascript Window Learning Notes