Creating objects in JavaScript using Object.create can sometimes cause issues in Internet

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");

Answer №1

Have you attempted debugging in Internet Explorer and inserting breakpoints within SharePoint's primary JavaScript document? Are you positive that the Object.create instances within the default JavaScript file are being accessed?

Answer №2

The issue arises from the incorrect usage of Object.create with improper arguments.

Instead of using Object.create({name:value}), they should be using

Object.create({name:{value:value}})
.

It is likely that they have their own implementation of Object.create, which conflicts with your existing implementation. Their code is likely executed after yours, causing confusion and errors due to assumptions about the order of script execution.

It is recommended to thoroughly examine their code for any definitions of Object.create and verify the sequence in which scripts are being executed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Vue.js: Disabling button on image carousel when there is no "next" photo accessible

This is my initial experience with Vue. I am attempting to assemble a slideshow using an array of images. I have successfully managed to disable the "previous" button when the user reaches the beginning of the slideshow, but I am encountering difficulties ...

Tips for managing the response from a POST request using jQuery

I'm currently working on sending data via POST to my ASP.Net MVC Web API controller and retrieving it in the response. Below is the script I have for the post: $('#recordUser').click(function () { $.ajax({ type: 'POST', ...

Exploring Angular 4's Capabilities: Navigating a Multi-Dimensional Array

I am currently working with a multi-dimensional array that has two keys, and it is structured as follows: user: any = {}; // The index is incremented within a for loop to add values to the user object (this part is functioning correctly) this.user[index++ ...

How can I bind the ID property of a child component from a parent component in Angular 2 using @Input?

I have a unique requirement in my parent component where I need to generate a child component with a distinct ID, and then pass this ID into the child component. The purpose of passing the unique ID is for the child component to use it within its template. ...

Tips for Implementing CdvPurchase.Store in Angular

Is there a way to configure cordova-plugin-purchase v13 in conjunction with Angular 15? Here is a snippet of what I have attempted. Below is my PaymentService class that is set to be provided at the root level. // payment.service.ts import { Injectable } ...

Steps for downloading a file attached to a gridview

It seems like I'm overlooking something quite straightforward. I am creating binary files that I am associating with a GridView. FileDownloadGrid.DataSource = downloadList; FileDownloadGrid.DataBind(); The part of the grid that interests me ...

What are the best ways to create image animations on top of other images using CSS or JavaScript?

Imagine if the first image is in black and white, while the second one is colored. How can we make the black and white image change to color after a timeout period, with an animation similar to loading progress bars? Is this achievable using CSS or JavaScr ...

Error encountered with nested v-for in Vue.JS causing null and undefined values to be thrown

Question Conclusion: A Vue component I am working on has the following data setup: conversations: null, currentConversation: null, There is a method that runs on mounted() to retrieve the user's conversations: /** * Method to retrieve the user&ap ...

Whenever the click event is triggered, Ajax is making numerous duplicate calls

Each time I click to fetch my content using an AJAX call, the calls end up duplicating themselves. I've tried various on-click events I came across on Stackoverflow threads, but unfortunately none of them seem to be solving the issue. $(document).rea ...

Extracting images from a PDF document in C# can be easily achieved using the iText7

In my approach to extracting images from a PDF, I am facing an issue where the subtype is always returning null. I am currently using the iText7 library, which is the latest version available. If anyone has experience working with this new library, I wou ...

Can someone explain the significance of this error message in Redux - Toolkit?

Encountered this error message while working with Redux-Toolkit, could someone explain its meaning? name:"ConditionError" message:"Aborted due to condition callback returning false." ...

Navigating redirects in Node.JS using HorsemanJs and PhantomJS

I've recently delved into using horseman.js for web scraping in node.js. However, I'm facing difficulty understanding its working mechanism and finding useful examples online. My primary objective is to log in to a platform and extract specific ...

Converting an array into a JavaScript Date object

I am currently working with an array of dates and looping through each element. The elements within the array are not date objects but rather strings, I believe. When I print each of the elements to the console, they appear as follows: 2015,09,19 2015,09, ...

Tips for sending arguments to react-highcharts?

While browsing through the documentation, I noticed that I can pass config in a certain way: render() { let config = this.config; return ( <div className="column"> <div className="ui segment"> ...

Guide on extracting a JSON Array element in C# for Infopath

I am new to programming and I recently created a C# Infopath Button that sends an SMS when clicked. Everything worked smoothly except for the response from the server. While I was able to display the response, I would like to only show a specific part of t ...

How come I'm not receiving an error message when I enter an incorrect email or password?

Whenever I try to log in with the wrong password and email, no error message is displayed. Instead, it simply logs me in and takes me to the main page. Can someone please assist me in implementing an error message display for incorrect login details? imp ...

Tips for inheriting and overriding controller methods in AngularJS with Java as the base language:

I have a simple controller and I want to create a new controller that is very similar to it, but without copying too much code. angular.module('test').controller('parentController', parentController); parentController.$inject = [' ...

Securing a fixed path in Express and Nodejs: Best practices

Using the latest versions of Node and Express, I have organized my project into two folders: public and secured. I want to restrict access to the secured folder to only authenticated users. I have implemented a custom login system, but now I am unsure of ...

Various options can be chosen to alter the margin

$('#cpseltop').change(function() { var a = $(this).val(); $('.cpselhide').hide(); $('#cpsel' + a).show(); }); .cpselect{ display:block; border:1px solid #999; border-radius:9px; outline:none; width:100%; padding:2px 5px; curso ...

An effective method for appending data to a multidimensional array in Google script

Is there a way to expand a multidimensional array of unknown size without relying on a Google Sheets spreadsheet to manage the data? I've searched everywhere but can't find an example for a 3-dimensional array. Here's the challenge I'm ...