Window. Open and window. showmodaldialog

Source: Internet
Author: User

Recently, an Iot project has a module: Air-Conditioning Control and TV control. Therefore, Windows is used. open and window. showmodaldialog. I think it will not be used frequently in the future. I just need to sort it out for you to view it later and will not forget it. I would also like to share with you!

Write the operations and code that you think are useful.

Setvalue ("iframe1", "iframediv ");

Window. Parent. Opener = NULL; // if this sentence is not added, the system will prompt you to close the inquiry window;

Window. Parent. Close ();

1. Window. Open
Article

1. Parent window operation on Child Window

Open the window and set the window size:

VaR win = NULL;

Win = Window. Open ("open.html", "win", "width = 200, Height = 200 ");

A. Control the window size

Maximize:

// Maximize the window

Function sonmaximize ()

{

If (WIN & Win. Open &&! Win. Closed)

{

Win. moveTo (-4,-4 );

Win. resizeTo (screen. availwidth + 8, screen. availheight + 8 );

} Else {

Alert ('window not opened or closed ');

}

}

 

Minimize:

// Minimize the window

Function sonminimize ()

{

If (WIN & Win. Open &&! Win. Closed)

{

Win. resizeTo (0, 0 );

Win. moveTo (0, window. Screen. width );

} Else {

Alert ('window not opened or closed ');

}

}

Close:

// Close the window

Function closeson ()

{

If (WIN & Win. Open &&! Win. Closed)

{

Win. Opener = NULL;

Win. Close ()

} Else {

Alert ('window not opened or closed ');

}

}

Refresh:

// Refresh

Function refreshson ()

{

If (WIN & Win. Open &&! Win. Closed)

{

Win. Location. Reload ();

Win. Focus ();

} Else {

Alert ('the window has not been opened or closed ');

}

}

View the window size:

Function viewsonsize ()

{

If (WIN & Win. Open &&! Win. Closed)

{

Alert(win.doc ument. Body. clientwidth + '* '{win.doc ument. Body. clientheight );

Win. Focus ();

} Else

{

Alert ('window not opened or closed ');

}

}

 

Valid value:

Alert(registry.doc ument. getelementbyid ("opendiv"). innerhtml );

 

Assignment:

Win.doc ument. getelementbyid ("opendiv"). innerhtml = "I Am a value from the parent window ";

 

2. subwindow operation window

 

Refresh:

Window. opener. Location. Reload ();

// The following method can also be used.

// Window. Parent. Location. href = Window. Parent. Location. href; 

Close this window:

// Close this window

Function closewindow ()

{// Window. opener. Opener = NULL;

Window. Close ();

}

 

Close the parent window:

// Close the parent window

Function closeparent ()

{// Firefox does not work. Use the following method

// Open Firefox and enter about: config in the address bar

// Find Dom. allow_scripts_to_close_windows and change it to true.

VaR isie = (navigator. appname = 'Microsoft Internet Explorer ')

If (isie) {// if it is IE

Window. opener. Opener = NULL;

Window. opener. Close ();

Window. Close ();

} Else {

Alert ("Firefox cannot be closed directly; the following settings are required: 1. Open Firefox, enter about: config in the address bar; 2. find Dom. allow_scripts_to_close_windows and change it to true ");

}

}

 

Valid value:

Alert(registry.opener.doc ument. getelementbyid ("opendiv"). innerhtml );

Assignment:

Extends extends opener.doc ument. getelementbyid ("opendiv"). innerhtml = "I'm a value passed from the subwindow open ";

Ii. Modal window

1. Parent window operation subwindow

Parent window JS Code:

VaR parvalue = "the variable value in the parent window is now displayed ";

VaR Hao = "hao Jianwei ";

Function showdailog (pagehref, title, height, width)

{

// -------------- Left position

// Screen. availheight declares the available width of the screen of the browser.

VaR dleft = (screen. availheight-height)/2;

// -------------- Top position

VaR dtop = (screen. availwidth-width)/2;

//---------------

 

VaR sret = Window. showmodaldialog (pagehref, window, title, "scrollbars = yes; resizable = no; help = no; status = no; center = yes; dialogtop = 25; dialogleft = "+ dleft +"; dialogtop = "+ dtop +"; dialogheight = "+ height +" PX; dialogwidth = "+ width +" PX ;");

// -------- Return

If (sret = "refresh") // The returned value is used to refresh the parent page.

{

Window. test = "true ";

Window. Location. Reload ();

Alert (window. test );

}

}

Function Test ()

{

Alert ("Method for successfully calling the parent window in the modal window ");

}

2. Modal window operation parent window

VaR parentwin = Window. dialogarguments;

 

Refresh:

Parentwin. Location. Reload ();

 

Valid value:

Alert(parentwin.doc ument. getelementbyid ("showmodaldialogdiv"). innerhtml) // obtain objects in the parent window

Alert ("I got the variable from the parent window >>>" + parentwin. parvalue); // get the variable in the parent window

 

Call the js method of the parent window:

Parentwin. Test (); // call the method in the parent window

 

Assignment:

Parentwin.doc ument. getelementbyid ("showmodaldialogdiv"). innerhtml = "I'm a value from the subwindow showmodaldialog ";

 

Close this window:

// Close this window

Function closewindow ()

{

Window. Parent. Close ();

}

 

Close the parent window:

// Close the parent window

Function closemodal ()

{

VaR isie = (navigator. appname = 'Microsoft Internet Explorer ')

If (isie) {// if it is IE

Window. Parent. Parent. Close ();

// Parentwin. Opener = NULL; if you replace the preceding line with this, the parent window cannot be closed,

Parentwin. Close ();

// Window. Parent. Close (); only the mode window can be closed. Currently, only the mode window is tested in IE6.

} Else {

Alert ("Firefox cannot be closed directly; the following settings are required: 1. Open Firefox, enter about: config in the address bar; 2. find Dom. allow_scripts_to_close_windows and change it to true ");

}

}

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.