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.
我使用这个jquery popup插件从这个链接在我的WordPress网站。它在所有浏览器上都运行良好,但是在IE11上给出了如下错误。
Any help is much appreciated.
非常感谢您的帮助。
9 个解决方案
#1
67
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:
正如其他人提到的,Object.assign()方法在IE中不受支持,但是有一个可用的polyfill,只需在你的插件声明之前包含它:
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
从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).
测试页面:http://jsbin.com/pimixel/edit?。html,js,输出(只是删除polyfill,以得到您在页面上得到的相同错误)。
#2
6
As per the documentation, Object.assign() is a new technology, part of the ECMAScript 2015 (ES6) standard
根据文档,Object.assign()是一种新技术,是ECMAScript 2015 (ES6)标准的一部分
https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Object/assign
https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Object/assign
And, it is not supported by IE.
而且,它不支持IE。
#3
6
A possible solution for this problem:
这个问题的一个可能的解决方案是:
Add the script legacy.min.js before the custombox.min.js
legacy.min添加脚本。js custombox.min.js之前
source: custombox github project
来源:custombox github项目
#4
5
@John Doe
@John能源部
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...
我从你的评论中知道你想在node/react stack中实现这个。这和最初的问题有很大的不同,你应该问你自己的问题;不管怎样,这是你需要做的……
You can use [es6-object-assign][1]. It is an ES6 Object.assign() "polyfill".
您可以使用[es6-object-assign][1]。它是ES6对象。assign()“polyfill”。
First, in package.json
in your root folder, add es6-object-assign
as a dependency:
首先,在包中。在根文件夹中的json,添加es6-object-assign作为依赖项:
"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...
如果你有问题在前面(浏览器)结束…将它添加到索引中。html文件…
<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
location_of_node_modules依赖于您所使用的样板文件,主要是node_modules,但有时当索引时。html位于需要使用的子目录../node_modules
#5
4
@Andres-Ilich has the right answer to your question but you're asking the wrong question:
@Andres-Ilich对你的问题有正确的答案,但你问错了问题:
Why not just use a jQuery plugin that supports IE like Zurb's excellent Reveal: https://github.com/zurb/reveal
为什么不使用jQuery插件来支持IE,比如Zurb的出色的Reveal: https://github.com/zurb/reveal
It will do everything you want and not throw this error.
它会做你想做的一切,而不会抛出这个错误。
#6
3
Currently working on a jQuery popup myself: https://github.com/seahorsepip/jPopup
目前使用的是jQuery弹出窗口:https://github.com/seapip/jpopup。
Has everything you'd expect of a popup and more :D
有你所期望的弹出窗口和更多: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...
不管怎样,回到主题,我现在正在写版本2,这是一个很大的重写,并且增加了对IE6的支持(版本1是IE7+),并且遇到了相似的错误……
Original code that gave the error in IE6:
给出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();
#7
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.
当某些html元素id与JavaScript函数中的某些变量具有相同的id时,通常会发生这些错误。在更改其中一个的名称之后,代码工作了。
Source : SCRIPT438: Object doesn't support property or method IE
对象不支持属性或方法IE
Other link : jquery validation IE Object doesn't support property
其他链接:jquery validation IE对象不支持属性
#8
2
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.
由于您使用jQuery标记了问题,所以可以使用jQuery扩展函数。不需要填充,它也可以进行深度合并。
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}
#9
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.
创建一个polyfill函数的实践是,它的行为方式与对象相同。分配(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.
我认为最好的解决方案是迭代一个又一个的参数,将参数对象的每个属性赋给目标,考虑对象和数组之间的迭代,以避免创建引用。可选地,为了不丢失实例,您可以检测属性的最后一个实例是否仅等于“Array”或“Object”,这样做的话,如果您打算创建新的引用,您就不会丢失图像接口(例如),但是具有这些实例的对象仍然是引用。
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.
根据这个溶液,我有我自己的聚填料可以在这里找到。
#1
67
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:
正如其他人提到的,Object.assign()方法在IE中不受支持,但是有一个可用的polyfill,只需在你的插件声明之前包含它:
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
从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).
测试页面:http://jsbin.com/pimixel/edit?。html,js,输出(只是删除polyfill,以得到您在页面上得到的相同错误)。
#2
6
As per the documentation, Object.assign() is a new technology, part of the ECMAScript 2015 (ES6) standard
根据文档,Object.assign()是一种新技术,是ECMAScript 2015 (ES6)标准的一部分
https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Object/assign
https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Object/assign
And, it is not supported by IE.
而且,它不支持IE。
#3
6
A possible solution for this problem:
这个问题的一个可能的解决方案是:
Add the script legacy.min.js before the custombox.min.js
legacy.min添加脚本。js custombox.min.js之前
source: custombox github project
来源:custombox github项目
#4
5
@John Doe
@John能源部
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...
我从你的评论中知道你想在node/react stack中实现这个。这和最初的问题有很大的不同,你应该问你自己的问题;不管怎样,这是你需要做的……
You can use [es6-object-assign][1]. It is an ES6 Object.assign() "polyfill".
您可以使用[es6-object-assign][1]。它是ES6对象。assign()“polyfill”。
First, in package.json
in your root folder, add es6-object-assign
as a dependency:
首先,在包中。在根文件夹中的json,添加es6-object-assign作为依赖项:
"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...
如果你有问题在前面(浏览器)结束…将它添加到索引中。html文件…
<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
location_of_node_modules依赖于您所使用的样板文件,主要是node_modules,但有时当索引时。html位于需要使用的子目录../node_modules
#5
4
@Andres-Ilich has the right answer to your question but you're asking the wrong question:
@Andres-Ilich对你的问题有正确的答案,但你问错了问题:
Why not just use a jQuery plugin that supports IE like Zurb's excellent Reveal: https://github.com/zurb/reveal
为什么不使用jQuery插件来支持IE,比如Zurb的出色的Reveal: https://github.com/zurb/reveal
It will do everything you want and not throw this error.
它会做你想做的一切,而不会抛出这个错误。
#6
3
Currently working on a jQuery popup myself: https://github.com/seahorsepip/jPopup
目前使用的是jQuery弹出窗口:https://github.com/seapip/jpopup。
Has everything you'd expect of a popup and more :D
有你所期望的弹出窗口和更多: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...
不管怎样,回到主题,我现在正在写版本2,这是一个很大的重写,并且增加了对IE6的支持(版本1是IE7+),并且遇到了相似的错误……
Original code that gave the error in IE6:
给出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();
#7
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.
当某些html元素id与JavaScript函数中的某些变量具有相同的id时,通常会发生这些错误。在更改其中一个的名称之后,代码工作了。
Source : SCRIPT438: Object doesn't support property or method IE
对象不支持属性或方法IE
Other link : jquery validation IE Object doesn't support property
其他链接:jquery validation IE对象不支持属性
#8
2
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.
由于您使用jQuery标记了问题,所以可以使用jQuery扩展函数。不需要填充,它也可以进行深度合并。
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}
#9
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.
创建一个polyfill函数的实践是,它的行为方式与对象相同。分配(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.
我认为最好的解决方案是迭代一个又一个的参数,将参数对象的每个属性赋给目标,考虑对象和数组之间的迭代,以避免创建引用。可选地,为了不丢失实例,您可以检测属性的最后一个实例是否仅等于“Array”或“Object”,这样做的话,如果您打算创建新的引用,您就不会丢失图像接口(例如),但是具有这些实例的对象仍然是引用。
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.
根据这个溶液,我有我自己的聚填料可以在这里找到。