Implementation of JavaScript Pop-up window class

Source: Internet
Author: User

JS print output is by Doucument.write (), the implementation of the document.write () can write variables, text text needs to be added "".

JS There are two ways to insert into the HTML page 1:<script> write JS code <script> This tag is placed in

Content, but because the code execution when the top-down if the JS code in the

2: Write a JS file (example 01js.js) through the <script src=01js.js><script> implementation of the introduction of JS code.

JS variables are implemented by the VAR keyword: var i=10; It is possible to define a numeric array string, such as a variable declared by VAR, to declare the value first, and the Declaration of the function in JS is implemented by the function+ function name.

function Mywin () {

JS Code

} function is to implement this code if an operation requires the code to directly refer to the function name.

Alert Warning is a small pop-up window. If you do not click OK, you will not be able to do anything else. If there are two or more alerts that pop up sequentially, alert () can be a numeric variable literal (plus ""), and in the pop-up window, something inside the alert is displayed.

Confirm is also a pop-up window he comes with a OK and Cancel button. So first define the variable var lll=confirm () This variable must be a Boolean variable so you need to if-else the statement

Example: Var lll=confirm ("Is this a number?") ");

if (lll==true) {

document.write ("yes");

}

else{

document.write ("not");

}

Prompt is also a pop-up window but you can enter text, the input text as a function return value, so should first define the function prompt (STR1,STR2) str1 is in the window is not modifiable, str2 is in the text box, the default text can be modified.

Example: function Mywin () {

var lll=prompt ("Please enter your phone", "fill in your phone here");

if (lll.lenght!=11) {

Alert ("Please enter the correct phone number");

}

else{

Alert ("Make a note of my friend");

}

}

Open a new window is generally implemented with the window.open () statement, window.open (URL, window name, parameter string); URL is the URL of the site that needs to be opened, if the URL is assigned to the return value of the function is the name of the variable, the window name refers to the URL location of the URL in the new form to open the form is what the window name is determined, the name is composed of alphanumeric and underscore In general there are a few more special names

1: "_blank" means to open this URL in a new window. 2: "_self" means to open this URL in the current window. 3: "_top": frames page in the upper window to display the target page (???? The name of the window is not required to create multiple windows in the same name.

Parameter strings are mainly used to decorate open URLs, such as the ability to modify the width of the Web page has no menu bar problems.

window.open () is often used in conjunction with prompt () to open a new Web page using the URL of the prompt input as the return value as the URL of the window.open.

Window close Window.close (); Used to close the window, the window's closing is generally used to assign the URL of the window to the variable, and then the variable (for example, the variable is lll) Lll.close (), to implement the window closure.

The window that will be opened is to use this method, Var lll=window.open ("http//:www.baidu.com"); Lll.close ();

Implementation of JavaScript Pop-up window class

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.