Discussion on mutual call of method variables of sub page parent page in js

  • 2021-07-09 06:39:17
  • OfStack

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

window. parent. Method () or variable name
window. parent is equivalent to the operation after navigating to the parent page and writing code in the parent page


window.parent.aa();// Retrieve aa Function 
window.parent.bb;// Retrieve bb Variable 

 For example, if you want to get it in a subpage id For aaa The value of the text box of 

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

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

(2) The parent page calls the child page

Mainly navigate to the sub-page through contentWindow


document.getElementById("childframe").contentWindow.childtest();
// Call the in the subpage childtest Method  js The writing style of 

var childWindow = $("#addFrame")[0].contentWindow;// Gets an object in a child form 
childWindow.formSubmit();// Object of a child page formSubmit Method  jquery The writing style of 
// Note: Among them  childframe And addFrame  Metropolitan time iframe Adj. id

Related articles: