59

I am using this jquery popup plugin from this link on my WordPress site. It's working fine on all browsers but giving the following error on IE11.

enter image description here

Dale K
  • 25,246
  • 15
  • 42
  • 71
pragya rai
  • 611
  • 1
  • 5
  • 3

11 Answers11

122

As others have mentioned, the Object.assign() method is not supported in IE, but there is a polyfill available, just include it "before" your plugin declaration:

if (typeof Object.assign != 'function') {
  Object.assign = function(target) {
    'use strict';
    if (target == null) {
      throw new TypeError('Cannot convert undefined or null to object');
    }

    target = Object(target);
    for (var index = 1; index < arguments.length; index++) {
      var source = arguments[index];
      if (source != null) {
        for (var key in source) {
          if (Object.prototype.hasOwnProperty.call(source, key)) {
            target[key] = source[key];
          }
        }
      }
    }
    return target;
  };
}

From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

Test page: http://jsbin.com/pimixel/edit?html,js,output (just remove the polyfill to get the same error you're getting on your page).

Andres I Perez
  • 75,075
  • 21
  • 157
  • 138
  • 3
    Why does it use single `!=` instead of safer `!==`? – Daniel Kucal Jan 09 '18 at 19:43
  • 1
    Thank you! This works beautifully. I was having this exact problem with the Facebook Customer Chat widget, and applying this code just before FB's code did the trick. (For the one client who still insists upon using IE even though the rest of the world has moved on) – Alex Russell May 14 '19 at 15:20
  • Something similar is available here https://www.npmjs.com/package/es6-object-assign -- I added it with npm install... and copied the automatic polyfill as suggested by `` –  May 14 '20 at 10:06
8

@John Doe

I figured out from your comment that you want to implement this in node/react stack. This is very different from original question and you should have asked your own ;)
Anyways, Heres what you need to do...

You can use [es6-object-assign][1]. It is an ES6 Object.assign() "polyfill".

First, in package.json in your root folder, add es6-object-assign as a dependency:

"dependencies": {
    "es6-object-assign": "^1.0.2",
    "react": "^0.12.0",
    ...
  },

Then if you want to use it in node environment use:

require('es6-object-assign').polyfill();

If you are having the issue on front (browser) end...
Add it in your index.html file...

<script src="location_of_node_modules/es6-object-assign/dist/object-assign.min.js"></script>
<script>
  window.ObjectAssign.polyfill();
</script>

location_of_node_modules depends on boilerplate you use, mostly just node_modules, but sometimes when index.html is in a subdirectory you need to use, ../node_modules

Community
  • 1
  • 1
shramee
  • 5,030
  • 1
  • 22
  • 46
7

As per the documentation, Object.assign() is a new technology, part of the ECMAScript 2015 (ES6) standard:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

And it is not supported by IE.

faintsignal
  • 1,828
  • 3
  • 22
  • 30
JGV
  • 5,037
  • 9
  • 50
  • 94
  • How do you implement a polyfill like https://www.npmjs.com/package/event-source-polyfill? In a node/react stack? – John Doe Aug 16 '16 at 04:08
6

A possible solution for this problem:

Add the script legacy.min.js before the custombox.min.js

source: custombox github project

aprovent
  • 941
  • 6
  • 20
3

@Andres-Ilich has the right answer to your question but you're asking the wrong question:

Why not just use a jQuery plugin that supports IE like Zurb's excellent Reveal: https://github.com/zurb/reveal

It will do everything you want and not throw this error.

serraosays
  • 7,163
  • 3
  • 35
  • 60
3

Currently working on a jQuery popup myself: https://github.com/seahorsepip/jPopup

Has everything you'd expect of a popup and more :D

Anyway back on topic, I'm currently writing version 2 which is a big rewrite and adds support for IE6 (version 1 was IE7+) and ran into a similiar error...

Original code that gave the error in IE6:

//Insane code for an insane browser
this._vars.fakeScrollbar = $("<div style=\"position:absolute;top:expression(document.documentElement.scrollTop);right:0;bottom:0;margin-left:-200px;width:0;overflow-y:scroll;height:expression(document.documentElement.clientHeight);z-index:9999999;\"></div>");

The hack I had to come up with:

//Insane code for an insane browser
this._vars.fakeScrollbar = $("<div>");
this._vars.fakeScrollbar.html("<div style=\"position:absolute;top:expression(document.documentElement.scrollTop);right:0;bottom:0;margin-left:-200px;width:0;overflow-y:scroll;height:expression(document.documentElement.clientHeight);z-index:9999999;\"></div>");
this._vars.fakeScrollbar = this._vars.fakeScrollbar.children();
seahorsepip
  • 4,519
  • 1
  • 19
  • 30
3

Since you tagged the question with jQuery you can use the jQuery extend function. No need for a polyfill and it does deep merge as well.

For Example:

var object1 = {
  apple: 0,
  banana: { weight: 52, price: 100 },
  cherry: 97
};
var object2 = {
  banana: { price: 200 },
  durian: 100
};

// Merge object2 into object1
$.extend( object1, object2 );

Result:

{"apple":0,"banana":{"price":200},"cherry":97,"durian":100}
Kalimah
  • 11,217
  • 11
  • 43
  • 80
3

please add script

<script src="https://cdn.jsdelivr.net/npm/es6-object-assign@1.1.0/dist/object-assign-auto.min.js"></script>

to html file to resolved this problem.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
HoangDo
  • 41
  • 2
2

These error usually occurs when some html element id has the same id as some variable in the JavaScript function. After changing the name of one of them code worked.

Source : SCRIPT438: Object doesn't support property or method IE

Other link : jquery validation IE Object doesn't support property

Community
  • 1
  • 1
Milap
  • 6,915
  • 8
  • 26
  • 46
1

Basically, Object.assign isn't supported by all browsers, however, it's possible to re-assign it at Object case it's not supported by the current browser.

It's pratice to make a polyfill function, which behaves in the same way as Object.assign(target, ...) of ES6.

I think the best solution is to iterate each argument after target, assign each property of arguments objects to target, considering a iteration between objects and arrays, to avoid creating references. Optionally, to not lost instances, you can detect if the last instance of the property is only equal to "Array" or "Object", and doing so you won't lost a Image interface (e.g) if you plan to create new references, but objects with these instances will still be reference.

Edit: the original Object.assign doesn't work in this way.

According to this solution, I've my own polyfill which can be found here.

Community
  • 1
  • 1
0

React solution for IE11

Regarding shramee's answer, which stated something like this:

@JohnDoe from your comment, you want to implement this in node/react stack. This is very different from the original question, but you might use es6-object-assign, an ES6 Object.assign() "polyfill":

This polyfill was updated and things can be done a bit differently now:

  • in package.json in your root folder, add es6-object-assign as a dependency (executing npm i in a command line after):

    "dependencies": {
        "es6-object-assign": "^1.0.2",
        "react": "^16.8.6",
        ...
      },
    

    Or simply run: npm i --save es6-object-assign

  • To use it in a node environment:

    require('es6-object-assign').polyfill();
    // Same version with automatic polyfilling
    require('es6-object-assign/auto');
    
  • To use it in your index.html, just add the automatic polyfill JS file reference to it (if you have scripts in the <body> that invoke Object.assign() you may add it at the end of the <head> element).

    1. Invoking directly from node_modules:

      <script src="location_of_node_modules/es6-object-assign/dist/object-assign-auto.min.js"></script>
      

      location_of_node_modules depends on your project structure (when index.html is in a subdirectory you might need: ../node_modules).

    2. However, this might have not worked for you (due to node_modules folders access, e.g. you are using create-react-app). If so, just copy the JS file from the dist/ node_modules folder to the public/ folder and then:

      <script src="%PUBLIC_URL%/object-assign-auto.js"></script>
      

      You might want to use the non-minified file and add other customized polyfills (e.g. startsWith).

CPHPython
  • 12,379
  • 5
  • 59
  • 71