I need to open a provider hosted app inside a SharePoint Modal Dialog. The provider hosted app is hosted in AZURE Web App Services. I have tried several examples that I could see in Microsoft documentation but it does not work. https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ff410058(v=office.14) Any suggestions please?
1 Answer
@Gabriel Bravo,
I created a get started SharePoint provided host add-in and deploy it on Azure web service. By means of below js code (through Content Editor web part), I can open the add-in web page in a dialogue.
<html>
<head>
<title>Page Title</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#savebtn").click(function () {
var options = SP.UI.$create_DialogOptions();
options.url = "https://sharepointaddinproviderweb.azurewebsites.net/Pages/Default.aspx?SPHostUrl=https%3A%2F%2Fisvdevchat%2Esharepoint%2Ecom%2Fsites%2Fsbdev&SPLanguage=en%2DUS&SPClientTag=8&SPProductNumber=16%2E0%2E20628%2E12006";
options.width = 600;
options.height = 400;
options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
SP.UI.ModalDialog.showModalDialog(options);
});
});
function CloseCallback(result, target) {
if (result == SP.UI.DialogResult.OK) {
// Run OK Code
alert('ok');
}
if (result == SP.UI.DialogResult.cancel) {
// Run Cancel Code
alert('cancel');
}
}
</script>
</head>
<body>
<h1>This is a Button</h1>
<input id="savebtn" type="button" value="Save" name="btnSave" />
</body>
</html>
The targeted URL is copied from the location where you click to open the provider add-in.
Test:
BR