2

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.

Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
  • 1
    What do you mean "from the dialog"? A dialog can't execute javascript... – benekastah Aug 21 '12 at 21:20
  • the `lauchDialog` function opens an aspx page in a modal window, so it can execute javascript. Maybe dialog was a poor choice of words, I was just going off of what SharePoint is calling it in their function. – Abe Miessler Aug 21 '12 at 21:22
  • When you say modal window. Are you talking about a new browser window, a div in the same page or iframe maybe? – Sebastian Aug 22 '12 at 00:36

2 Answers2

0
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

Community
  • 1
  • 1
Lemex
  • 3,772
  • 14
  • 53
  • 87
  • Hrrm this is close, but in my example I don't have access to the `callbackTester` function. In my example `callbackTester` would open a modal window, where I could execute some javascript. `callbackTester` would be the equivalent of my `launchDialog` method. – Abe Miessler Aug 21 '12 at 21:40
  • hmm ill seee what i can come up with – Lemex Aug 21 '12 at 21:47
0

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;
});
elclanrs
  • 92,861
  • 21
  • 134
  • 171
  • So would the external variable be available to javascript that runs from the modal window that opens? – Abe Miessler Aug 21 '12 at 21:50
  • I don't know, depends on your environment, but shouldn't be hard to test. In any case you can always store your app config in a separate file `app_config.js` that you load whenever you need it. – elclanrs Aug 21 '12 at 21:52
  • Keep in mind I haven't tested this myself. I'm just thinking this might work but maybe it's more complicated than it seems... – elclanrs Aug 21 '12 at 21:54
  • Unfortunately I doesn't look like I have access to `myApp.returnValue` from my modal window. Any suggestions for getting around that? – Abe Miessler Aug 21 '12 at 21:57