I have been working on software development for SharePoint 2013, specifically dealing with overriding SharePoint's file previewer (changing filepreview.debug.js to myfilepreview.debug.js). Unfortunately, we have encountered a problem with IE8, while everything seems to be working fine in IE9.
The error occurring in IE8 triggers an issue on any site within the site collection where our custom feature is activated, displaying the message "Object does not support this property or method".
After researching this error, it seems that IE8 does not support Object.create
, as indicated in this Mozilla Developer post. To address this, we added a polyfill code snippet before the problematic line:
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() { }
F.prototype = o;
return new F();
};
}
It seems that this workaround resolved the issue by mimicking the functionality of Object.create, which is not supported in IE8.
What's puzzling is that SharePoint's file previewer javascript, which also utilizes Object.create, works perfectly fine. The even stranger part is that the section of code causing the error in our javascript is actually SharePoint's code. Our entire javascript code up to that point is identical to SharePoint's, except for a few lines.
Here is the default code up to the problematic line:
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;
},
// more code here...
};
})();
blankPreview = Object.create(previewBase); <--- error occurs here
The only difference between SharePoint's javascript and ours up to this point is the removal of two lines at the beginning. Adding them back did not resolve the issue:
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");
So, my question is: Why do we receive the error that Object.create is not supported in IE8 when the same function is used without problems in the default SharePoint javascript code?
EDIT: A suggestion from another forum user was to try registering my script via SOD. I added this to my code, but it had no effect:
RegisterSod("MyFilepreview.debug.js", "_layouts/15/MyFilepreview.debug.js");