I'm trying to upload a file and to show the Upload.aspx dialog from an external web site. I have this code:
function openUploadNewDocumentDialog(passingID)
{
var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url = appWebUrl + "/_layouts/15/Upload.aspx?List=%7B" + documentLibraryId + "%7D&IsDlg=1";
dialogOptions.width = 700;
dialogOptions.height = 310;
dialogOptions.title = "Upload Document";
SP.UI.ModalDialog.showModalDialog(dialogOptions);
}
I have this HTML code:
<input id="openSpDialogButton" type="button" value="Open SP dialog" onclick="openUploadNewDocumentDialog()" />
I also have alot of script includes from SharePoint, such as: sp.js, sp.core.js, sp.ui.dialog.js, sp.runtime.js, init.js, core.js, MicrosoftAjax.js etc. These seems to be necessary in order to display the modal dialog.
The URL works fine when I use it in a new browser tab but when I try to call the above function from an button I get this CORS error: Refused to display
'https://example.sharepoint.com/sites/Testsite/_layouts/15/Upload.aspx?List=%7B3b62f560-1244-4e6d-14f4-fe7b97238a0d%7D&IsDlg=1&IsDlg=1' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
I'm targeting SharePoint Online and probably SharePoint 2016 and maybe SharePoint 2013 but not SharePoint 2010. I'm no stranger to really new features in SharePoint but I still can't get this to work.
I read about the SP.RequestExecutor.js that was added in SP2013 that should solve CORS issues but I'm not really sure how to use it when displaying the Upload.aspx dialog? For REST calls sure but how do I use it for showModalDialog()?
I found these two articles related to this problem but I don't think they offer me a solution:
- https://blogs.msdn.microsoft.com/officeapps/2012/12/12/iframing-sharepoint-hosted-pages-in-apps/
- https://blogs.msdn.microsoft.com/officeapps/2012/11/29/solving-cross-domain-problems-in-apps-for-sharepoint/
Any help is appreciated, thanks!
Access-Control-Allow-Origin
is hard coded to"*"
regardless of yourweb.config
setting.