Mutual call between parent page and child page

1. Subpages opened with open in the page:

1. The child page calls the method of the parent page, including the child page passing values ​​to the parent page:  

   

window.opener.methodName();
window.opener.methodName(param1,param2);
 

 

2. The parent page closes the child page: on the parent page 

   

openWin=window.open("");
function bClick(){
     openWin.close();
}

 

 

2. In the subpage of the Iframe

   The child page assigns a value to the Div of the parent page

   

parent.window.document.getElementByIdx_x('id').innerHTML='';

 

   Call the method of the parent page

   

window.parent.window.methodName();

 

   refresh parent page

  

window.parent.location.reload();

 

 

 

open open properties

 

window.open (pageURL, name, parameters)

 
Among them:
pageURL is the sub-window path
name is the sub-window handle
parameters are the window parameters (parameters are separated by commas)

Parameter | Value range | Description

alwaysLowered | yes/no | Specifies that the window is hidden behind all windows
alwaysRaised | yes/no | Specifies that the window is suspended above all windows depends |
yes/no | Whether to close the parent window at the same time
directories | yes/ no | Whether the directory bar of Nav2 and 3 is visible
height | pixel value | Window height
hotkeys | yes/no | Set safe exit hotkey in windows without menu bar
innerHeight | pixel value | The pixel height of the document in the window
innerWidth | pixel value | The pixel width of the document in the window
location | yes/no | whether the location bar is visible
menubar | yes/no | whether the menu bar is visible
outerHeight | pixel value | set the pixel height of the window (including decorative borders)
outerWidth | pixel value | set Pixel width of the window (including decorative borders)
resizable | yes/no | whether the window can
be resized screenX | pixel value | the pixel length of the window from the left border of the screen
screenY | pixel value | the pixel length of the window from the upper border of the screen
scrollbars | yes/ no | Whether the window can have a scroll bar
titlebar | yes/no | Whether the window title bar is visible
toolbar | yes/no | Whether the window toolbar is visible or not
Width | pixel value | The pixel width of the window
z-look | yes/no | Whether the window floats on top of other windows when activated

 

(1) The child page calls the method or variable of the parent page:

The window.parent. method () or the variable name
window.parent is equivalent to locating the parent page. The operation after locating the parent page is the same as writing code in the parent page.

window.parent.aa();//Call the aa function
window.parent.bb;//Call the bb variable

For example: want to get the value of the text box with id aaa in the sub page

window.parent.$("#aaa").val();//The premise of this writing is to refer to jquery

window.parent.getElementById("aaa").value; //js writing

 (2) The parent page calls the child page

Mainly through contentWindow to locate the child page

 
document.getElementById("childframe").contentWindow.childtest();
//Call the childtest method js in the child page
1. The parent page gets the child page element: (jquery writing)
    Format: $("#iframe ID").contents().find("#iframe control ID").click();
    Example: $("#ifm").contents().find("#iBtnOk").click(); // ifm is the <iframe> tag id; iBtnOk is the subpage button id
 
2. The parent page calls the child page method:
    Format: $("#iframe ID")[0].contentWindow.iframe method();
    Example: $("#ifm")[0].contentWindow().iClick(); // ifm is the <iframe> tag id; iClick is the subpage js method
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326265449&siteId=291194637
Recommended