Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript Object.create and IE8
    primarykey
    data
    text
    <p>I'm doing software development for SharePoint 2013. Part of this involves overriding SharePoint's file previewer (filepreview.debug.js becomes myfilepreview.debug.js). We've run into problems, however, with IE8. Everything works just fine in IE9.</p> <p>The error thrown in IE8 causes an error on any site you visit within the site collection that our custom feature is activated on: "Object does not support this property or method"</p> <p>After doing some research on this error, it would <em>appear</em> that IE8 simply does not support <code>Object.create</code>. <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create">This Mozilla Developer post</a> seems to support this theory. I was more pressed to believe this when the issue was solved by adding this polyfill code before the line that was throwing the error:</p> <pre><code>if (typeof Object.create !== 'function') { Object.create = function (o) { function F() { } F.prototype = o; return new F(); }; } </code></pre> <p>I guess that would make sense that it works because it mimics the functionality of Object.create which supposedly isn't supported in IE8.</p> <p>However, this was confusing because SharePoint's file previewer javascript works just fine. Their javascript <em>also</em> uses Object.create. Even weirder, the section of code that was throwing the error in our javascript wasn't even our code -- it's SharePoint's. The entire javascript code up to then is actually the same as SharePoint's as well, except for a few lines.</p> <p>Here's the default, up to the line in question:</p> <pre><code>function $_global_filepreview() { RegisterSod("mediaplayer.js", "_layouts/15/mediaplayer.js"); RegisterSod("sp.publishing.resources.resx", "/_layouts/15/ScriptResx.ashx?name=sp.publishing.resources&amp;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 ['&lt;div class="js-filePreview-containingElement" id=', StAttrQuote(this.fpDomId), '&gt;', this.getInnerHtml(), '&lt;/div&gt;'].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 ['&lt;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 + '"&gt;', '&lt;img src="', "/_layouts/15/images/gears_anv4.gif", '" /&gt;', '&lt;/div&gt;'].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); &lt;--- error is thrown here </code></pre> <p>The only difference between the SharePoint javscript (above) and ours (up to this point) is we've removed these following two lines from the beginning, though adding them back still doesn't solve the issue:</p> <pre><code>RegisterSod("sp.publishing.resources.resx", "/_layouts/15/ScriptResx.ashx?name=sp.publishing.resources&amp;culture=" + STSHtmlEncode(Strings.STS.L_CurrentUICulture_Name)); RegisterSodDep("mediaplayer.js", "sp.publishing.resources.resx"); </code></pre> <p>So my question is: Why am I getting this error that Object.create isn't supported in IE8 while other uses of the same exact function in the default javascript work without issue?</p> <p>EDIT: A user on another forum suggested I try registering my script via sod. I added this to my code without effect:</p> <pre><code>RegisterSod("MyFilepreview.debug.js", "_layouts/15/MyFilepreview.debug.js"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload