Sharepoint - SP.UI.ModalDialog.showModalDialog using the html option
May not be the best wat but it works:
var test = "<div id='correspondence'>" + result + "</div>";
$('body').append(test);
SP.UI.ModalDialog.showModalDialog({
html: document.getElementById('correspondence'),
title: "Correspondence",
allowMaximize: false,
showClose: true,
autoSize: true
});
Here's a better way than the code from John by using plain JavaScript (no need for jQuery) and without adding the element to the body manually:
var element = document.createElement('div');
element.innerHTML = 'Hello World, I am the dialog content';
SP.UI.ModalDialog.showModalDialog({
html: element,
title: 'My Dialog Title',
allowMaximize: false,
showClose: true,
autoSize: true
});
The html
option takes a DOM element rather than a string because of which you get this error. Try something like this:
var htmlElement = document.createElement('p');
var messageNode = document.createTextNode('Message');
htmlElement.appendChild(messageNode);
var options = {
html: htmlElement,
autoSize: true,
allowMaximize: true,
title: 'Title',
showClose: true,
};
var dialog = SP.UI.ModalDialog.showModalDialog(options);
The above code snippet has been taken from here.