Home >Web Front-end >HTML Tutorial >When the js parent page calls the child page data, the child page calls back the parent page through the parameters passed by the parent page. Specific method_html/css_WEB-ITnose

When the js parent page calls the child page data, the child page calls back the parent page through the parameters passed by the parent page. Specific method_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:57:27970browse

When I was writing code today, I found that multiple places on the same page need to call the same subpage. If multiple methods are called, the same subpage will call back the parent page method, which will cause problems, so I checked the information and let this function General, call back the specific parent page method according to the specific method. By the way, to summarize, I hope it will be useful in the future, maybe it can help people who need help


Use here eval() function

Definition and usage

eval() function can calculate a string and execute it JavaScript code.



The path of the parent page calling the child page (the path of the child page) is 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 the callback of the parent page


                                                                                                                                                                                                                                                      . '','' names '')');                                                                                                                                                               
function getParams(key) {
var href = window.document.location.href;

if (href.indexOf("?") != -1) {

var paramStr = href. substring(href.indexOf("?") 1, href.length);
                                                                                                                                                                                                   Key "="),

Paramstr.Length);

if (Paramstr.Indexof ("&")! = -1) {
Return Paramstr.substring (paramstr.indexof ("=") 1 , paramStr
.indexOf("&"));
. } else {
.                       paramStr.length);
                               
          } else {
                     return "";

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn