While working with SharePoint / JavaScript modal pop up you might encounter error "cannot read property 'showmodaldialog' of undefined". Here is simple solution for that.
Code Sample:
function OpenDocsDialog(url1) {
var options = {
url: url1,
dialogReturnValueCallback: myDialogCallback
};
SP.UI.ModalDialog.showModalDialog(options); // this line gives error.
}
Solution : We need to load "sp.js" file before calling above code. You can load "sp.js" file with below code sample:
ExecuteOrDelayUntilScriptLoaded(function () { //code }, "sp.js")
Full solutionExample :
function OpenDocsDialog(url1) {
var options = {
url: url1,
dialogReturnValueCallback: myDialogCallback
};
ExecuteOrDelayUntilScriptLoaded(function () {
SP.UI.ModalDialog.showModalDialog(options);
}, "sp.js")
}
Subscribe to:
Post Comments (Atom)
-
In last blog we learn how can we enable footer on SharePoint Online Modern Communication site. If you have not gone through that you can use...
-
Recently I was working with search bar in search result page where I encounter below error: Sorry, Something went wrong An error occurred...
-
SharePoint Designer 2013 – a tool that is most useful few years back, still handy in some projects, and that still gives me trouble when nee...
No comments:
Post a Comment