Two common methods for Js pop-up box port and Return Value

Source: Internet
Author: User

1. window. showModalDialog (url, args, dialogattrs)
Parameter description:
Url: the url of the pop-up page.
Agrs: parameters passed to the dialog box in the main window, which can be of any type (array or)
Dialogattrs: style parameters in the pop-up window
Mode dialog box usage:
Main window: var value = window. showModalDialog ('test. js', strs, 'resizable: Yes ');
In the pop-up box, use window. returnValue to set the return value. The value obtained above is the value, and you can
This value is processed for interaction.
Note: the application of the mode dialog box lies in its return value. It can return simple escape characters or arrays. The non-mode dialog box is similar
2. Window. open:
Parent window]
Copy codeThe Code is as follows:
<Script>
Function show_child ()
{
Var child = window. open ("child.html", "child", "height = 200, width = 400, status = yes, toolbar = no, menubar = no, location = no ");
/* If (! Child. closed)
{
If (! Window. close ())
{
Var textValue = frm.txt. value; parent.frm0.txt 0. value = textValue;
}
Else
{
Window. close ();
Child. close ();
}
}*/
}
</Script>
<A href = "javascript: show_child ();"> open a subwindow </a>
<Form name = frm0>
<Input type = "text" name = "txt0" id = "txt0"> // note that the ID attribute must be written here. Otherwise, the value cannot be obtained under FF.
</Form>

Subwindow]
Copy codeThe Code is as follows:
<Script>
Function choseItem ()
{
Var v = "";
Var check_item = document. frm. item;
For (I = 0; I <check_item.length; I ++)
{
If (check_item [I]. checked)
{
V + = "," + check_item [I]. value;
}
Document.frm.txt. value = v. replace (/^, {1 }/,"");
}
}
Function foo ()
{
Window. close ();
Window .opener.doc ument. getElementById ("txt0"). value = document. getElementById ("txt"). value
}
</Script>
<Body>
<Form name = frm>
<Input type = checkbox name = item value = 1 onclick = "choseItem ();">
<Input type = checkbox name = item value = 2 onclick = "choseItem ();"> B
<Input type = checkbox name = item value = 3 onclick = "choseItem ();"> c
<Input type = checkbox name = item value = 4 onclick = "choseItem ();"> d
<Input type = text name = "txt" id = "txt">
</Form>
<Input type = button value = "close" onclick = "foo ();">
</Body>

Summary: windows. because there are many user-defined open, windows is used. there are many open pages. Many Web editors prefer showModalDialog. If you don't know which one to use, you can use window. open. Many mature cms systems use Windows. open.

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.