加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – JavaScript Object.create和IE8

发布时间:2020-12-15 08:41:28 所属栏目:百科 来源:网络整理
导读:我正在为SharePoint 2013进行软件开发.其中一部分涉及覆盖SharePoint的文件预览器(filepreview.debug.js成为myfilepreview.debug.js).但是,我们遇到了IE8的问题.在IE9中一切正常. IE8中引发的错误会导致您在网站集中访问的任何网站上出现错误,我们的自定义功
我正在为SharePoint 2013进行软件开发.其中一部分涉及覆盖SharePoint的文件预览器(filepreview.debug.js成为myfilepreview.debug.js).但是,我们遇到了IE8的问题.在IE9中一切正常.

IE8中引发的错误会导致您在网站集中访问的任何网站上出现错误,我们的自定义功能已激活:“对象不支持此属性或方法”

在对此错误进行一些研究之后,IE8似乎根本不支持Object.create. This Mozilla Developer post似乎支持这一理论.当问题通过在抛出错误的行之前添加此polyfill代码来解决问题时,我更加迫切地相信这一点:

if (typeof Object.create !== 'function') {
    Object.create = function (o) {
        function F() { }
        F.prototype = o;
        return new F();
    };
}

我想这有意义,因为它模仿了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:','px; text-align:center; vertical-align:middle; display: inline-block; ' + customStyle + '">','<img src="',"/_layouts/15/images/gears_anv4.gif",'" />',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

SharePoint javscript(上面)和我们的(直到这一点)之间的唯一区别是我们从一开始就删除了以下两行,但添加它们仍然无法解决问题:

RegisterSod("sp.publishing.resources.resx","sp.publishing.resources.resx");

所以我的问题是:为什么我得到这个错误,IE8中不支持Object.create,而在默认的javascript中使用相同的确切函数没有问题?

编辑:另一个论坛上的用户建议我尝试通过草皮注册我的脚本.我将此添加到我的代码中没有效果:

RegisterSod("MyFilepreview.debug.js","_layouts/15/MyFilepreview.debug.js");

解决方法

尝试在IE中进行调试,并将断点放在SharePoint的默认JavaScript文件中.你确定默认JavaScript中的Object.create实例真的被击中了吗?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读