JS Window object Common content

Source: Internet
Author: User

The Window object represents the windows of the browser. If the document contains a frame (frame or iframe label), the browser creates a Window object for the HTML document and creates an additional window object for each frame.

There are no frames, and in one frame, window is one, so window can omit writing.

It has many properties and methods.

Navigator getting information about your browser

Screen gets the information

History contains URLs that users have visited in a browser window.

Location contains information about the current URL.

Here are two timers in window, SetInterval and settimeout

These two timers are different, setinterval is to achieve a certain period of time, and constantly repeated execution.

and settimeout means to execute once after a certain amount of time has been reached.

<! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Content-type"Content="Text/javascript"/> <title>testjs</title> <style type="Text/css"> </style>"Div1">asdad</div> <button id="Stop"> Time Stop </button> <button id="STOP1"> Cancel sayhello</button> <script type="Text/javascript">function Time () {varDate =NewDate (); document.getElementById ("Div1"). InnerText =date; }        vargettime = SetInterval ("Time ()", -); The time function is executed every 500 milliseconds, so the page times are constantly refreshed document.getElementById ("Stop"). onclick =(function () {//Add event to button, stop refresh Time clearinterval (gettime) when clicked; }) function SayHello () {alert ("Hello"); }        varHello = SetTimeout ("SayHello ()", the); After 5 seconds, execute the SayHello function document.getElementById ("STOP1"). onclick =function () {//To add an event to the button, 5 seconds after the click does not execute functions cleartimeout (hello); }    </script></body>

The Window object also has the most common dialog box.

Alert () Displays a warning box with a message and a confirmation button.

Comfirm () displays a dialog box with a message along with a confirmation button and a Cancel button.

Prompt () Displays a dialog box to prompt the user for input.

123<script type= "Text/javascript" >4 functiondisp_prompt ()5   {6   varName=prompt ("Please enter your name", "" ")//The first parameter asks the message, and the second parameter is the value entered. Returns the value entered7   if(name!=NULL&& name!= "")8     {9document.write ("Hello" + name + "!"))Ten     } One   } A functiondisp_confirm () -   { -   varR=confirm ("Press a Button")//parameter is the prompt message, click Confirm to return True, cancel return false the   if(r==true) -     { -document.write ("You pressed ok!")     -     } +   Else -     { +document.write ("You pressed cancel!") A     } at   } - functionDisplay_alert ()//warning message box, popup message, only confirmation button, no return information -   { -Alert ("I am an alert box!!") -   } -</script> in -<body> to  +<input type= "button" onclick= "Display_alert ()" -value= "Display alert box"/> the  *</body> $

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.