The problem of passing parameters from the subpage opened by window.open() to the main page

<!--Code of main page--> 
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script type="text/javascript" src="../../commonJS/jquery.js"></script> <script> </script> </head> <body> <div style="width:140px; height:60px; position:relative;display:inline-block;background-color: red; margin-right:20px;display:inline-block;cursor: pointer;" id="addMatchSchedule"> </div> </body> </html> <script> $("#addMatchSchedule").click(function() {alert("a"); window.open('child.html',"新增","width=500,height=480,screenX=400,screenY=100"); } ); //The function called by the sub page window.BBBB = function(){ alert(112); } </script>  
<!--Subpage--> 
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <script src="../../commonJS/jquery.js"></script> <body> <a class="btn btn-small btn-info" onclick="addSchduleItem();" title="确定" >确定</a> </body> </html> <script> // OK to close the page function addSchduleItem() { if (window.opener != null && !window.opener.closed) { window.opener.BBBB();//Call the function of the main page } window.close(true);  } </script>

  

Summarize the idea in one sentence: open the child window in the parent window, and call the method of the parent window in the child window

Core method: window.open() (the method is introduced at the end of this article)

Core concept: window.opener (the method is introduced at the end of this article)

Introduction to window.open() (take a specific situation as an example):

  window.open('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no , status=no') //This sentence is written as a line of code

   Parameter explanation:
       window.open is the command to pop up a new window; 
  'page.html' is the file name of the pop-up window; 
  'newwindow' is the name of the pop-up window (not the file name), optional, and can be replaced with empty ''; 
  height=100 window height ; 
  width=400 window width; 
  top=0 the pixel value of the window from the top of the screen; 
  left=0 the pixel value of the window from the left side of the screen; 
  toolbar=no whether to display the toolbar, yes to display; 
  menubar, scrollbars represent the menu bar and scroll bar. 
  resizable=no is allowed to change the size of the window, yes is allowed; 
  location=no is whether the address bar is displayed, yes is allowed; 
  status=no is whether the information in the status bar is displayed (usually the file has been opened), yes is allowed;

 

Introduction to window.opener

window.opener is actually the parent form of the child form opened through window.open

Guess you like

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