Understanding dialog boxes in JavaScript

Source: Internet
Author: User

Previous words

Usually we use alert () When we are debugging a program, if we need to block the effect. In addition to alert (), the Window object provides 3 other dialog boxes. This article describes the dialog box in detail in the Window object

Defined

The System dialog box does not have a relationship with the Web page that is displayed in the browser, nor does it contain HTML. Their appearance is determined by the operating system and browser settings, not by CSS. The common dialog box under the Window object has alert (), confirm (), prompt (), and, of course, print (), which is not commonly used. The dialog boxes that are opened by these methods are both synchronous and modal. That is, the code stops executing when the dialog box is displayed, and the code resumes execution when the dialog box is turned off

Alert ()

The alert () method takes a string and displays it to the user and waits for the user to close the dialog box

[Note] The method contains the default string () implicit type conversion, and non-string types are converted to strings

<div id= "Mydiv" > click here </div><script>function() {    alert ([+]);   'i ' </script>

Confirm ()

The Confirm () method also receives a string and displays it to the user. The Boolean value returned if True means that clicking Ok,false means clicking Cancel or the Close button in the upper-right corner

<div id= "Mydiv" > click here </div><script>function() {    if( Confirm (' Do you want to add a background color? ') {        = ' Pink ';    } Else {        = ' Transparent ';        Alert (' Well, then don't add the background color. ')    }}</script>

Prompt ()

The prompt () method receives two parameters, the text prompt to display to the user, and the default value of the text input field (which can be an empty string). Returns the value of the text input field if the user clicked the OK button, or if the user clicked Cancel or the Close button in the upper-right corner, the method returns null

<div id= "Mydiv" > click here </div><script>function() {    var result = Prompt ("Can you tell me what is the name?", "Match");     if NULL {        if(result = = ' Match ') {            alert (' match is my name Oh ');        } Else {            alert ("welcome you," +result);         }    } Else {        alert (' Well, welcome, anonymous. I used to think that anonymity was a writer's name ');}    } </script>

Print ()

The Window.print () method can be used to display the Print dialog box

<div id= "Mydiv" > click here </div><script>function() {    window.print ();} </script>

Understanding dialog boxes in JavaScript

Related Article

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.