SP2013 SharePoint托管的应用程序模态对话框错误:无法读取'hiddenButtonValueBeforeDialog'

时间:2014-06-27 17:49:05

标签: sharepoint sharepoint-2013

我只是想证明在我的SharePoint托管的应用页面中显示模式对话框的概念。我相信我已经包含了所需的js库,并且在执行我的函数之前,我给它足够的时间来加载库。我收到的错误是:

无法读取未定义的属性'hiddenButtonValueBeforeDialog'

我相信我有我需要的库::

<script type="text/javascript" src="/_layouts/15/init.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/SP.UserProfiles.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.ui.dialog.js"></script>

使用Javascript:

function showDialog() {

var optDict = {
    width: 800,
    height: 500,
    url: 'http://www.google.com',
    title: "Upload your file"
};

try {
    SP.UI.ModalDialog.showModalDialog(optDict);
}
catch (err) {
    alert(err.message);
}

    return false;
}

2 个答案:

答案 0 :(得分:9)

错误Cannot read property 'hiddenButtonValueBeforeDialog' of undefined发生,因为sp.ui.dialog.js是全球化的JavaScript库,并且尚未在客户端加载所需的资源文件SP.Res.resxSP.Res.hiddenButtonValueBeforeDialog生成从这个文件)。

解决方案

  1. ScriptResx HTTP处理程序用于加载资源的内容 客户端的文件,必须添加以下行:

    <script type="text/javascript" src="/_layouts/15/ScriptResx.ashx?name=sp.res&culture=en-us"></script>
    
  2. 此外,由于SP.UI.UIUtility存在依赖关系 sp.ui.dialog.js库中的命名空间,sp.init.js JavaScript 必须引用库:

    <script type="text/javascript" src="/_layouts/15/sp.init.js"></script>
    

答案 1 :(得分:0)

我在PlaceHolderMain中添加了所有这些引用

<script src="/_layouts/15/1033/init.js" type="text/javascript"></script>
<script src="/_layouts/15/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/_layouts/15/ie55up.js" type="text/javascript"></script>    
<script src="/_layouts/15/sp.core.js" type="text/javascript"></script>
<script type="text/javascript" src="/_layouts/15/ScriptResx.ashx?name=sp.res&culture=en-us"></script>
<script type="text/javascript" src="/_layouts/15/sp.init.js"></script>
<script src="/_layouts/15/sp.ui.dialog.js" type="text/javascript"></script>
<script src="/_layouts/15/core.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.runtime.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.js" type="text/javascript"></script>
<script src="/_layouts/15/inplview.js" type="text/javascript"></script>
<script src="/_layouts/15/cui.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.ribbon.js" type="text/javascript"></script>
<script src="/_layouts/15/mdn.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.ui.pub.ribbon.js" type="text/javascript"></script>
<script src="/_layouts/15/msstring.js" type="text/javascript"></script>
<script src="/_layouts/15/socialdata.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.ui.socialribbon.js" type="text/javascript"></script>
<script src="/_layouts/15/cui.js" type="text/javascript"></script>
<script src="/_layouts/15/wpadder.js" type="text/javascript"></script>
<script src="/_layouts/15/search.js" type="text/javascript"></script>

现在所有的javascript错误都消失了