When the JS parent page invokes the child page data, the child page passes through the parent page The parameter callback the parent page concrete method

Source: Internet
Author: User

Write code today found that the same page multiple places need to call the same child page, if more than one method call, the same sub-page callback parent page method will be a problem, so check the information, let this function generalized, according to specific method callback specific parent page method, by the way, I hope that later can be useful, Maybe to help people in need of help.


Use the eval() function here

Definition and usage

The eval () function computes a string and executes the JavaScript code in it.



The path to the child page called by the parent page (the path to the child page) is as follows

Http://localhoust:8080/oss-portlet/html/util/area.html?oid=4&name= Test &callback=callbackdistrict

callback: parameter is the specific method name of the parent page


The child page calls the parent page of the callback specified method


eval (' Window.opener ' + getparams ("callBack") + ' (\ ' + ids + ' \ ', \ ' + names + ') ');

Window.close ();


/**
* Get page Path parameter values
*/
function Getparams (key) {
var href = window.document.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 "";
}
}
}

When the JS parent page invokes the child page data, the child page passes through the parent page The parameter callback the parent page concrete method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.