Javascript Window Learning Notes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.