Object #<Object> has no method 'showModalDialog'
-
10-12-2019 - |
Question
Consider the following code:
var options = {
title: 'Create a new Post'
autoSize: true,
url: url
}
SP.UI.ModalDialog.showModalDialog(options);
The code is executed from a ECB custom action and from a web part. It works fine in IE, however when i call it from the webpart in Google Chrome it gives the following error:
Uncaught TypeError: Object # has no method 'showModalDialog'
The strange thing is that when i call the exact same code (it's part of my library) from the ECB custom action it now works in Google Chrome!
I've tried calling it with
ExecuteOrDelayUntilScriptLoaded
_spBodyOnLoadFunctionNames.push("funcname")
LoadSodByKey("sp.ui.dialog.js", null);
Any ideas or help? It's driving me crazy!
Solution
This is a Chrome issue with it's caching model.
Please make sure you call
LoadSodByKey("SP.UI.Dialog.js", null);
To ensure the file is loaded.
OTHER TIPS
This specified error that is encountered in Chrome browser, could be eliminated by using SP.SOD.execute(key, functionName, args) Method.
Replace the line
SP.UI.ModalDialog.showModalDialog(options);
with the
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);