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.
11 comments
Comments are closed.
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.
Comments are closed.
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:
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).
@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, addes6-object-assign
as a dependency:Then if you want to use it in node environment use:
If you are having the issue on front (browser) end…
Add it in your index.html file…
location_of_node_modules
depends on boilerplate you use, mostly justnode_modules
, but sometimes when index.html is in a subdirectory you need to use,../node_modules
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.
A possible solution for this problem:
source: custombox github project
@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.
Currently working on a jQuery popup myself:
https://github.com/seahorsepip/jPopup
Has everything you’d expect of a popup and more ๐
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:
The hack I had to come up with:
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:
Result:
please add script
to html file to resolved this problem.
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
Basically,
Object.assign
isn’t supported by all browsers, however, it’s possible to re-assign it atObject
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 ofarguments
objects totarget
, 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 aImage
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.
React solution for IE11
Regarding shramee’s answer, which stated something like this:
This polyfill was updated and things can be done a bit differently now:
in
package.json
in your root folder, addes6-object-assign
as a dependency (executingnpm i
in a command line after):Or simply run:
npm i --save es6-object-assign
To use it in a node environment:
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 invokeObject.assign()
you may add it at the end of the<head>
element).Invoking directly from
node_modules
:location_of_node_modules
depends on your project structure (when index.html is in a subdirectory you might need:../node_modules
).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 thedist/
node_modules folder to thepublic/
folder and then:You might want to use the non-minified file and add other customized polyfills (e.g.
startsWith
).