tnw*_*tnw 6 javascript c# sharepoint internet-explorer-8 sharepoint-2013
我正在为SharePoint 2013进行软件开发.其中一部分涉及覆盖SharePoint的文件预览器(filepreview.debug.js成为myfilepreview.debug.js).但是,我们遇到了IE8的问题.在IE9中一切正常.
IE8中引发的错误会导致您在网站集中访问的任何网站上出现错误,我们的自定义功能已激活:"对象不支持此属性或方法"
在对此错误进行一些研究后,似乎 IE8根本不支持Object.create.这篇Mozilla开发者帖子似乎支持这一理论.当问题通过在抛出错误的行之前添加此polyfill代码来解决问题时,我更加迫切地相信这一点:
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() { }
F.prototype = o;
return new F();
};
}
Run Code Online (Sandbox Code Playgroud)
我想这有意义,因为它模仿了Object.create的功能,据说IE8不支持它.
但是,这很令人困惑,因为SharePoint的文件预览器javascript工作得很好.他们的javascript 也使用Object.create.甚至更奇怪,在我们的javascript中抛出错误的代码部分甚至不是我们的代码 - 它是SharePoint的.到目前为止,整个javascript代码实际上与SharePoint相同,除了几行.
这是默认值,直到有问题的行:
function $_global_filepreview() {
RegisterSod("mediaplayer.js", "_layouts/15/mediaplayer.js");
RegisterSod("sp.publishing.resources.resx", "/_layouts/15/ScriptResx.ashx?name=sp.publishing.resources&culture=" + STSHtmlEncode(Strings.STS.L_CurrentUICulture_Name));
RegisterSodDep("mediaplayer.js", "sp.publishing.resources.resx");
previewBase = (function() {
ULS7RK:
;
var filePreviewUniqueId = 0;
return {
init: function(ctxT, listItem, extension) {
this.fpId = ++filePreviewUniqueId;
this.fpDomId = "FilePreviewID-" + String(this.fpId);
this.fpCtx = ctxT;
this.fpExtension = extension;
this.fpListItem = listItem;
},
getHtml: function() {
ULS7RK:
;
return ['<div class="js-filePreview-containingElement" id=', StAttrQuote(this.fpDomId), '>', this.getInnerHtml(), '</div>'].join("");
},
getDomId: function() {
ULS7RK:
;
return this.fpDomId;
},
getContainingElement: function() {
ULS7RK:
;
var containingElement = document.getElementById(this.fpDomId);
Sys.Debug.assert(m$.isElement(containingElement), "Containing element has not been rendered yet.");
return containingElement;
},
canRender: function() {
ULS7RK:
;
return true;
},
getLoadingIndicatorHtml: function(customStyle) {
if (m$.isUndefined(customStyle)) {
customStyle = "";
}
return ['<div class="js-filePreview-loading-image" style="width:', this.getWidth(), 'px; height:', this.getHeight(), 'px; line-height:', this.getHeight(), 'px; text-align:center; vertical-align:middle; display: inline-block; ' + customStyle + '">', '<img src="', "/_layouts/15/images/gears_anv4.gif", '" />', '</div>'].join("");
},
hideLoadingIndicator: function() {
ULS7RK:
;
var containingElement = document.getElementById(this.fpDomId);
((m$(containingElement)).find("div.js-filePreview-loading-image")).css({
display: "none"
});
},
getInnerHtml: function() {
ULS7RK:
;
return "";
},
getWidth: function() {
ULS7RK:
;
return null;
},
getHeight: function() {
ULS7RK:
;
return null;
},
onPostRender: function() {
},
onVisible: function() {
},
onHidden: function() {
}
};
})();
//**This is where the "fix" was added originally**
blankPreview = Object.create(previewBase); <--- error is thrown here
Run Code Online (Sandbox Code Playgroud)
SharePoint javscript(上面)和我们的(直到这一点)之间的唯一区别是我们从一开始就删除了以下两行,但添加它们仍然无法解决问题:
RegisterSod("sp.publishing.resources.resx", "/_layouts/15/ScriptResx.ashx?name=sp.publishing.resources&culture=" + STSHtmlEncode(Strings.STS.L_CurrentUICulture_Name));
RegisterSodDep("mediaplayer.js", "sp.publishing.resources.resx");
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:为什么我得到这个错误,IE8中不支持Object.create,而在默认的javascript中使用相同的确切函数没有问题?
编辑:另一个论坛上的用户建议我尝试通过草皮注册我的脚本.我将此添加到我的代码中没有效果:
RegisterSod("MyFilepreview.debug.js", "_layouts/15/MyFilepreview.debug.js");
Run Code Online (Sandbox Code Playgroud)
尝试在 IE 中进行调试,并在 SharePoint 的默认 JavaScript 文件中放置断点。您确定默认 JavaScript 中的 Object.create 实例确实被命中了吗?
| 归档时间: |
|
| 查看次数: |
2683 次 |
| 最近记录: |