简体   繁体   中英

How to set value from call back function?

I am working with some existing javascript and I have the following code:

launchDialog(myUrl,function(result, returnValue){
   //whatever
});

This code launches a modal window and when that window closes, the callback function fires.

What I am wondering is if it is possible for me execute some javascript from the modal that will allow me to set the returnValue parameter of my callback function?

FYI:

Not sure if it matters, but this is a dumbed-down version of some existing SharePoint javascript. I cannot change the functionality of the lauchDialog function, but I can add javascript to the modal and the callback function.

function tryMe (param1, param2) {
    alert(param1 + " and " + param2);
}

function callbackTester (callback) {
    callback (arguments[1], arguments[2]);
}

callbackTester (tryMe, "hello", "goodbye");

Theres an example, i think thats what your trying to do.

Used the follow source for example: JavaScript: Passing parameters to a callback function

If I understand your question correctly you could store the returnValue in an external variable that is shared with the modal.

var myApp = {}; // your namespace
myApp.returnValue = 'something'; // you can override this wherever

launchDialog(myUrl, function(result, returnValue){
   returnValue = myApp.returnValue;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM