When the js parent page calls the child page data, the Child page calls back the specific method of the parent page through the parameter passed over the parent page
When I wrote the code today, I found that the same subpage needs to be called in multiple places on the same page. If multiple methods are called, the method of the parent page callback on the same subpage will fail, so I checked the information, to make this function generic, callback the specific parent PAGE method based on the specific method. By the way, I hope it will be useful in the future and may help people who need help.
Used hereEval() Function
Definition and usage
The eval () function computes a string and executes the JavaScript code.
The parent page calls the sub-page path (the Sub-page path) as follows:
Http: // localhoust: 8080/oss-portlet/html/util/area.html? Oid = 4 & name = Test & callBack = callBackDistrict
Callback:The parameter is the specific method name of the parent page.
The child page calls the method specified by callback of the parent page
Eval ('window. opener. '+ getParams ("callBack") +' (\ ''+ ids + '\', \'' + names + '\')');
Window. close ();
/**
* Get the page path parameter value
*/
Function getParams (key ){
Var href = too many Doc ument. location. href;
If (href. indexOf ("? ")! =-1 ){
Var paramStr = href. substring (href. indexOf ("? ") + 1, href. length );
If (paramStr. indexOf (key + "= ")! =-1 ){
ParamStr = paramStr. substring (paramStr. indexOf (key + "= "),
ParamStr. length );
If (paramStr. indexOf ("&")! =-1 ){
Return paramStr. substring (paramStr. indexOf ("=") + 1, paramStr
. IndexOf ("&"));
} Else {
Return paramStr. substring (paramStr. indexOf ("=") + 1,
ParamStr. length );
}
} Else {
Return "";
}
}
}