Actions between a JavaScript (Iframe, window.open, window.showmodaldialog) parent window and a child window

Source: Internet
Author: User

First, the Iframe article

Public part

The parent object gets the value of the child window//objectid is the window identifier, ContentID is the element idfunction GetValue (objectid,contentid) {var Isie = (Navigator.appname = = ' M                                      Icrosoft Internet Explorer ') if (Isie) {//IE                                                    Alert (Document.frames (ObjectID) document.getElementById (ContentID). InnerHTML); } else {//If it is FF alert (document.getelementby                                   Id (ObjectID). Contentdocument.getelementbyid (ContentID). InnerHTML); InnerText is not supported under FF;  Here's how to fix//if (document.all) {//                                   Alert (document.getElementById (' Div1 '). InnerText);                                   } else{//Alert (document.getElementById (' Div1 '). textcontent); }}}//Parent object Assigning values to child window//objectidis the window ID, ContentID is the element idfunction SetValue (objectid,contentid) {var Isie = (Navigator.appname = = ' Microsoft Internet Explorer ') if (Isie) {//If it is IE document.frames (ObjectID). document.ge                                           Telementbyid (ContentID). innerhtml= "I was assigned by IE under the parent window"; } else {//if it is FF document.getElementById (ObjectID). contentdocument.getelemen                                 Tbyid (ContentID). innerhtml= "I was assigned by the parent window under FF"; }     }

1. Parent window Action on child window

Refresh:      document.getElementById ("Iframeid"). Src=document.getelementbyid ("Iframeid"). src+ "? _=" +math.random (); This method sometimes needs to handle the "src" attribute. Value://Parent window takes the value of child window       GetValue ("Iframe1", "Iframediv"); Assignment://parent window sets the value of the window element;       SetValue ("Iframe1", "Iframediv");        

2. Child window Operation parent window

           Refresh:           (1), window.parent.location.href=window.parent.location.href;              (2), window.parent.location.reload ();                  Value: Alert (window.parent.document.getElementById ("Iframediv"). InnerHTML);      Assignment: Window.parent.document.getElementById ("Iframediv"). Innerhtml= "I am the value passed from the child window iframe"; Closed: window.parent.opener=null;//If you do not add this sentence, you will be prompted to close the Inquiry window; window.parent.close ();

Second, window.open article

1. Parent window Action on child window

Open: Var win=null;win=window.open ("Open.html", "Win", "width=200,height=200"); Maximized://Window maximized function sonmaximize () {if (win&&win.open&&!win.closed) {Win.moveto (-4              ,-4);       Win.resizeto (SCREEN.AVAILWIDTH+8,SCREEN.AVAILHEIGHT+8);       }else{alert (' has not yet opened the window or has been closed '); }} Minimized://Window minimized function sonminimize () {if (win&&win.open&&!win.closed) {win.resize              to (0,0);       Win.moveto (0,window.screen.width);       }else{alert (' has not yet opened the window or has been closed '); }} Close://Close Window function Closeson () {if (win&&win.open&&!win.closed) {Win.open              Er=null;       Win.close ()}else{alert (' Not yet open window or closed '); }} Refresh://Flush function Refreshson () {if (win&&win.open&&!win.closed) {win.location.re              Load ();       Win.focus ();       }else{alert (' window is not open or closed '); }} View window size: function VIEWSONSize () {if (win&&win.open&&!win.closed) {alert (win.document.body.clientwidth+ ' *              ' +win.document.body.clientheight);       Win.focus ();       }else {alert (' not yet open window or closed '); }} Value: Alert (window.document.getElementById ("Opendiv"). InnerHTML); Assignment: Win.document.getElementById ("Opendiv"). Innerhtml= "I am the value passed from the parent window";

2. Child window Operation window

 refresh: Window.opener.location.reload ();     The following method can also be//window.parent.location.href=window.parent.location.href;       Close this window://close this window function CloseWindow () {//window.opener.opener=null; Window.close ();} Close parent window://Close parent window function closeparent () {//Firefox does not work if you want to work.  Use the following method//Open Firefox, enter about:config in the Address bar//Find dom.allow_scripts_to_close_windows This and change to true var Isie = (Navigator.appname = = ' Microsoft Internet Explorer ') if (Isie) {//If it is IE win                     Dow.opener.opener=null;                     Window.opener.close ();                    Window.close (); }else{alert ("Firefox cannot be closed directly; The following settings are required 1." To open Firefox, enter about:config;2 in the Address bar. Find Dom.allow_scripts_to_close_windows and change to              True ");       }} Value: Alert (window.opener.document.getElementById ("Opendiv"). InnerHTML);     Assignment: Window.opener.document.getElementById ("Opendiv"). Innerhtml= "I am the value passed from the Subwindow open"; 

Iii. Modal Window Chapter

1. Parent Window Action child window

The parent Window JS code: VAR parvalue= "Now shows the value of the variable in the parent window"; var hao= "Jiang Jianwei"; function Showdailog (pagehref,title,height,width) {       //--------------Left position       // Screen.availheight declares the available width of the Display browser's screen       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 +";d ialogtop= "+ dtop +";d ialogheight= "+Height+" PX; Dialogwidth= "+width+" PX; ");       --------return       if (Sret = = "Refresh")//This is the use of the return value to refresh the parent page       {              window. Test= "true";              Window.location.reload ();                           Alert (window. Test);}       } function test () {       alert ("Method for the modal window to invoke the parent window successfully");}

2. modal window operation parent window

var parentwin=window.dialogarguments;  Refresh: ParentWin.location.reload (); Value: Alert (parentWin.document.getElementById ("Showmodaldialogdiv"). InnerHTML)//Get object in parent window alert ("I am the variable I get from the parent window >       >> "+parentwin.parvalue);    Get a variable in the parent window call the parent window JS method: Parentwin.test ();        Call a method in the parent window to assign a value: ParentWin.document.getElementById ("Showmodaldialogdiv"). Innerhtml= "I am the value passed from the Subwindow ShowModalDialog";  Close this window://close this window function CloseWindow () {window.parent.close ();} Close parent window://Close parent window function Closemodal () {var Isie = (Navigator.appname = = ' Microsoft Internet Explorer ') if (Isie) {//If it is IE win                     Dow.parent.parent.close ();                     Parentwin.opener=null; If you replace the above with this line, you cannot close the parent window, Parentwin.close (); Window.parent.parent.parent.parent.close (); This can only be turned off the modal window itself is currently only tested under IE6}else{alert ("Firefox cannot directly shut     The following settings are required 1. Open Firefox, enter about:config;2 in the Address bar. Find Dom.allow_scripts_to_close_windows and change to true ");         }     } 

Actions between a JavaScript (Iframe, window.open, window.showmodaldialog) parent window and a child window

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.