Is there an event handler I could use to determine when sharepoint launches a modal?
3 Answers
with Javascript you can try using the following
function showdialogfunction(pageUrl) {
var options = { url: pageUrl, width: 800, height: 600 };
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}
if you want to set focus mouse on the dialog then use the following script
$("#id").click(function () {
OpenPopUpPage("XXX.aspx", null, null, null)
setTimeout(setFocusModalDialog, 100);
return false;
})
});
function setFocusModalDialog() {
var iframe = $(".ms-dlgFrame")[0];
iframe.contentWindow.focus();
}
-
Not sure what this is trying to do or how it helps? For example, I need to set keyboard/mouse focus inside the model once it loads.– BatmanMay 16, 2017 at 1:39
-
To my knowledge there is no OOTB event handler being provided to us by the SP API. You might want to look at the following post: SP 2010 JavaScript events
In my library SharepointPlus I created a customized showDialogModal
function with more options, and one of them is onurlload
that triggers when the called URL is loaded.
To do it I check when the iframe (created by Sharepoint to load the URL of the modal) triggers the DOMContentLoad (using iFrameReady
from https://stackoverflow.com/a/24603642/1134119).
This solution only works if the URL is in the same domain (because of the cross-domain security restriction).
-
The problem i have though is that I need to hooking into SharePoint's built in showDialogModal. For example, when you hit new Document, it opens a modal but it doesn't set the cursor focus inside that modal, so now I need to set the focus when this happens. Can you library help with that?– BatmanMay 16, 2017 at 12:35
-
No it cannot. In your case you have to overwrite the default
SP.UI.ModalDialog.showModalDialog
or, theOpenPopUpPageWithDialogOptions()
function... Good luck– AymKdnMay 16, 2017 at 16:12