1

I have a SP 2010 page, where I have several links that open modal windows with the following code:

function OpenModalPage(url, title) {
var myModalPageOptions = SP.UI.$create_DialogOptions();
    myModalPageOptions.url = url;
    myModalPageOptions.title = title;
    myModalPageOptions.allowMaximize = true;
    myModalPageOptions.showClose = true;
    myModalPageOptions.width = 600;
    myModalPageOptions.dialogReturnValueCallback = Function.createDelegate(null, silentCallbackModalDialog);
return SP.UI.ModalDialog.showModalDialog(myModalPageOptions);
}
function silentCallbackModalDialog(dialogResult, returnValue) {}

I'm looking to call this function from another event as opposed to clicking. This isn't hard, but what I need to is "check" when the content has loaded.

Is there a function or property I can check in SP.UI.ModalDialog or SP.UI.Dialog that gets set to true once the content has loaded?

The other idea I have is to check the HTML content of everything that is loaded in the modal, and when I have HTML content, then its loaded. But I'm wondering if there is a better way.

I went through a bunch of Microsoft's documentation but I couldn't find what I was looking for. Thanks for the help!

  • Your requirement is not clear. Why you want to find DialogLoaded from the parent? – Amal Hashim Nov 18 '14 at 15:47
  • I'm using a tool similar to Intro.JS to showcase information on a page. Some of that information is in a modal window. So, I need to call a function, load some data (in this case, the HTML for the modal window), then when everything is loaded use Intro.JS to attach a tool-tip to some elements within the modal. – romellem Nov 18 '14 at 16:07
  • Dialog should be targeted to a particular page. Why can't you put this logic in that page? – Amal Hashim Nov 18 '14 at 16:09
  • I'm not sure I quite follow. Do you mean set some global variable in JS on the source of the modal window, then check if that variable is true / set? – romellem Nov 18 '14 at 16:36
  • no myModalPageOptions.url = url; here you are assigning a URL. Open that page and put the JavaScript logic for tooltip in that page. – Amal Hashim Nov 18 '14 at 16:39
2

An easy way would be to use the code below

var intervalDialogue = setInterval(function () {
    var dialog = SP.UI.ModalDialog.get_childDialog();
    if (dialog != null && dialog.$e_0 != null) {
        clearInterval(intervalDialogue);
    }
    else {
        console.log("waiting for popup to load");
    }
},500);

This will look for the changes in the HTML of the opened modal box and as soon as the HTML(dialog.$e_0) is available, the contents are loaded for the modal.

0

I was able to solve this but check the HTML of the iframe. This was my initial idea, and although it isn't ideal and seems to have a fair amount of overhead for a simple check, it is working for me.

function OpenModalPage(url, title) {
  var myModalPageOptions = SP.UI.$create_DialogOptions();
      myModalPageOptions.url = url;
      myModalPageOptions.title = title;
      myModalPageOptions.allowMaximize = true;
      myModalPageOptions.showClose = true;
      myModalPageOptions.width = 600;
      myModalPageOptions.dialogReturnValueCallback = Function.createDelegate(null, silentCallbackModalDialog);
  return SP.UI.ModalDialog.showModalDialog(myModalPageOptions);
}
function silentCallbackModalDialog(dialogResult, returnValue) {}


function OpenModalAndCallWhenLoaded(url, title, callback) {
  var modal = OpenModalPage(url, title);

  var contentLoadedTimeout = setTimeout(function(){console.log("contentLoaded TimeOut");clearInterval(contentLoaded);},20000);
  var contentLoaded = setInterval(function() {
    var $modal = $(modal.get_frameElement());
    if ($modal.contents().find("form[action='"+modal.get_url()+"?IsDlg=1']").length) {
      clearInterval(contentLoaded);
      clearTimeout(contentLoadedTimeout);
      callback();
      return true;
    };
  }, 100);
}

function itIsLoaded() {
  console.log("It worked!");
  //Do other stuff here
}

OpenModalAndCallWhenLoaded('/my/page/index.aspx', 'My Sample Page', itIsLoaded);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.