0

I have Ribbon button that when it's clicked you get a dialog window open. On that window I have a button that I want to use to close the dialog window when clicked.

This is the code for the dialog

 HostWebDialog="TRUE"
 HostWebDialogWidth="480"
 HostWebDialogHeight="240">

and on the App.js file I have a click function

$("#Blue").click(function () {



});

I use Visual Studio 2013 and SharePoint online, I want to do it with javascipt

EDIT

Right answer

window.parent.postMessage('CloseCustomActionDialogRefresh', '*');
window.parent.postMessage('CloseCustomActionDialogNoRefresh', '*');
  • Please post an answer with your answer, do not add it as an edit to your question (it makes it impossible for future readers to find it with ease) – Robert Lindgren Sep 22 '14 at 10:45
  • ok då vet jag hur jag ska göra – linkan94 Sep 22 '14 at 12:17
1

So if SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult, returnVal) is not working you can try this:

Closing the Dialog Autohosted and Provider-hosted Apps for SharePoint are hosted outside of SharePoint, and as such can’t leverage typical SharePoint scripts to close the dialog (ex: SP.UI.ModalDialog.commonModalDialogClose()). Luckily, I have hunted through many lines of core.js to find you the solution! Similar to resizing app parts (client web parts), we can use the HTML5 postMessage API to close the dialog from the app (and optionally refresh the parent page). This shouldn’t come as a surprise, since the postMessage API was meant to provide cross-domain communication and is used in other app scenarios. CloseCustomActionDialogRefresh and CloseCustomActionDialogNoRefresh are the two messages SharePoint is “listening” for to close the dialog. I wrapped these in a simple function I can releverage across all my apps:

 function closeParentDialog(refresh) {
    var target = parent.postMessage ? parent : (parent.document.postMessage ? parent.document : undefined);
    if (refresh)
        target.postMessage('CloseCustomActionDialogRefresh', '*');
    else
        target.postMessage('CloseCustomActionDialogNoRefresh', '*');
}
  • Hi i find that post but did't get it to work :/ – linkan94 Sep 19 '14 at 14:24
  • 1
    Here the same recommendation: msdn.microsoft.com/en-us/library/office/…. window.parent.postMessage('CloseCustomActionDialogRefresh', ''); window.parent.postMessage('CloseCustomActionDialogNoRefresh', ''); – Ruslan Dayanov Sep 19 '14 at 14:32

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.