微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – JavaScript Object.create和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实例真的被击中了吗?

原文地址:https://www.jb51.cc/csharp/244503.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐