I am developing software for SharePoint 2013. Part of this includes overriding the preview of a SharePoint file (filepreview.debug.js becomes myfilepreview.debug.js). However, we ran into problems with IE8. Everything works fine in IE9.
The error that occurred in IE8 causes an error on any site that you visit in the site collection to which our custom function is activated: "The object does not support this property or method"
After Object.create some research on this error, it looks like IE8 just doesn't support Object.create . This Mozilla developer post seems to support this theory. I was more eager to believe this when the problem was solved by adding this polyfill code before the line that generated the error:
if (typeof Object.create !== 'function') { Object.create = function (o) { function F() { } F.prototype = o; return new F(); }; }
I suppose it would be reasonable that it works because it mimics the functionality of Object.create, which is supposedly not supported in IE8.
However, this is confusing because the javascript JavaScript viewer works fine. Their javascript also uses Object.create. Even the stranger section of code that threw the error in our javascript was not even our code - this is SharePoint. All javascript code before this actually matches SharePoint, with the exception of a few lines.
Here's the default value, down to the corresponding 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; }, 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() { } }; })();
The only difference between Java javscript (above) and ours (up to this point) is that we deleted these two lines from the very beginning, although adding them did not solve the problem:
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 am I getting this error that Object.create is not supported in IE8, while other uses of the same exact function in the default javascript work without problems?
EDIT: A user in another forum suggested trying to register my script through sod. I added this to my code without effect:
RegisterSod("MyFilepreview.debug.js", "_layouts/15/MyFilepreview.debug.js");