SharePoint 2010:创建模式对话框时出现 JavaScript 错误?
由于某种原因,我的 SharePoint 模式对话框无法正常工作。我得到的错误是这样的:
- 在 Firefox 中:
SP.UI.$create_DialogOptions 不是函数
- 在 IE 中:
对象不支持此属性或方法
这是我的代码:
var options = SP.UI.$create_DialogOptions();
options.width = 525;
options.height = 300;
options.url = '/_layouts/mywork/richtexteditor.aspx';
options.dialogReturnValueCallback = Function.createDelegate(null, function (result, value)
{
alert(result + value);
});
SP.UI.ModalDialog.showModalDialog(options);
有趣的是,当我在 Firebug 中检查 SP.UI 时,我没有看到所有方法和属性。
注意:我使用的是标准 Web 部件(非视觉部件),而不是应用程序页面。
For some reason, my SharePoint's modal dialog doesn't work properly. The error I get is this:
- In Firefox:
SP.UI.$create_DialogOptions is not a function
- In IE:
Object doesn't support this property or method
Here is my code:
var options = SP.UI.$create_DialogOptions();
options.width = 525;
options.height = 300;
options.url = '/_layouts/mywork/richtexteditor.aspx';
options.dialogReturnValueCallback = Function.createDelegate(null, function (result, value)
{
alert(result + value);
});
SP.UI.ModalDialog.showModalDialog(options);
Interestingly, when I inspect the SP.UI in Firebug, I don't see all the methods and properties.
NOTE: I am using standard Webpart (not visual) and not an application page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题是所需的 SharePoint JavaScript“库”尚未加载。(SharePoint 2010 JS 有点混乱,命名空间/等来自各地 - 问题是新的“按需”加载进一步复杂化)。
使用SP2010模态对话框界面(包括
$create_DialogOptions
和showModalDialog
)需要加载的库是“sp.js”。确保“sp.js”已加载:
回调函数仅在“sp.js”(包括
SP.UI.ModalDialog
内容)被保证后调用被加载(如果出现加载错误,它可能永远不会被调用)。这也可以通过使用
到sp.js
并指定OnDemand
来解决,但我不能保证它:(我认为这种方法可能存在问题,但我不记得为什么我刚刚查看的项目中没有使用它。)参见SPSOD 了解更多详细信息/信息。
快乐编码。
The problem is that the required SharePoint JavaScript "Library" hasn't been loaded. (The SharePoint 2010 JS is a good bit of a mess and namespaces/etc. come from all over -- the matter is further complicated with the new "on demand" loading).
The library that needs to be loaded to use SP2010 Modal Dialog interface (including the
$create_DialogOptions
andshowModalDialog
) is "sp.js".To ensure "sp.js" is loaded:
The call-back function is only invoked after "sp.js" (including the
SP.UI.ModalDialog
stuff) is guaranteed to be loaded (and it may never be called if there is a loading error).This could also likely be solved with using a
<ScriptLink>
tosp.js
withOnDemand
specified, but I can't guarantee it: (I think there may have been issues with this approach, but I can't recall why it's not used in the project I just looked at.)See SPSOD for some more details/information.
Happy coding.
对我来说它是这样工作的:
ExecuteOrDelayUntilScriptLoaded(function () {}, "sp.js")
以及:
For me it worked like this:
ExecuteOrDelayUntilScriptLoaded(function () {}, "sp.js")
and:
发现Adela 和user166390 的方法在旧的IE 7-8 中都失败了。似乎页面没有完全解析并尝试通过对话框的 iframe 进行修改,这对那些 IE 来说是不好的。对于我的情况 - 我需要在应用程序页面中自动弹出对话框 - 我用 next
这个小东西
注册了所有 SP javascript 来修复它。
该方法可在 MSDN 论坛。
Found that both Adela's and user166390's approaches fail in old IEs 7-8. Seems that page is not completely parsed and tried to be modified by dialog's iframe and this is bad for those IEs. For my case - I need to auto-popup dialog in application page - I fixed it with next
This little thing
registers all SP javascripts.
The approach was found on MSDN forums.
您可以通过使用选项的通用对象而不是 DialogOptions 类来解决此问题。这意味着您必须像这样编写选项:
有关使用它的更多信息,请访问:
http://msdn.microsoft.com/en -us/library/ff410058%28v=office.14%29.aspx
并查看示例。
You can fix this issue by using a generic object for option instead of the DialogOptions class. that mean you have to write option like this:
for more information about using it, visit:
http://msdn.microsoft.com/en-us/library/ff410058%28v=office.14%29.aspx
and see the example.