I need to get rid or skip FormData.entries() in IE11. I have the code to check for IE 11 from here:
https://stackoverflow.com/a/22242528/1824579
var formData = new FormData();
...
if (!navigator.appVersion.indexOf('Trident/') > -1) { //is 29 in IE; -1 in Chrome
for (var pair of formData.entries()) { //error in IE11
...
}
}
So all I want to achieve is, that if the Browser is IE11 it should skip this section. By now I am not able to achieve this. In the console i only get this error shown up:
SCRIPT1004: Expected ';' Index(1094, 31) which is exactly after the word pair in this line: for (var pair of formData.entries()) {
I don't know why IE11 is coming so far, because a log or the result of navigator.appVersion.indexOf('Trident/') is 29 in IE11.
for...of is not supported in IE11. This is a syntax-level issue that can't be solved by feature detection. Your best bet is to transpile your source code with something like Babel, targeting IE11.
The issue might be with using the logical NOT operator. Checking "indexOf > -1" should do the trick or you may need to use an extra set of brackets:
if (!(navigator.appVersion.indexOf('Trident/') > -1))
Related
https://caniuse.com/#search=find states The find() method is not supported by IE11.
At the same time I'm testing this find() method in IE11 and I didn't find any traces of any wrong behavior.
I've also tested in IE11 the code
function isPrime(element, index, array) {
var start = 2;
while (start <= Math.sqrt(element)) {
if (element % start++ < 1) return false;
}
return (element > 1);
}
console.log([4, 5, 8, 12].find(isPrime)); // 5
from
SO: Array.prototype.find() is undefined
Yes, in IE11 it returns the expected result of 5 instead of TypeError: undefined is not a function, as SO: Array.prototype.find() is undefined in 2014 stated.
So... Am I missing something and IE11 really doesn't work properly with Array.prototype.find , or the last updates of IE11 that were made a while ago (but later than the SO question above was discussed in 2014) became to support this method?
Is https://caniuse.com/#search=find correct when says IE11 doesn't support Array.prototype.find ? Any evidence?
Thank you.
UPD: here is the screen of my IE11:
Everything you have read is correct. There is something flawed about your tests. Perhaps you included a Polyfill that added the method in IE11.
You can try following steps to validate:
Open a blank tab in IE.
Open console in dev tools.
Enter following code: [1,2,3].find(function(n) { !!n; })
If above code throws error (which it should), you are using a polyfill. Hence your code does not break.
If it works, only explanation is that somehow, some update has added its definition. But this is very unlikely as MS has stopped support for it.
This is what I get:
from many articles I have chosen this syntax to make unique values in an array.
pairs = pre_final_pairs.filter((elem, index) => pre_final_pairs.indexOf(elem) === index).join(' ');
This works perfectly in all browsers except Internet Explorer 11.
I have tried to find which of the command from the line is not compatible and I found that maybe the indexOf. But even if I tried to apply "fix" referred in How to fix Array indexOf() in JavaScript for Internet Explorer browsers still the page is not working in the IE11.
Also I have loaded https://code.google.com/archive/p/ddr-ecma5/ library in order to ensure that the ECMA commands will work.
And still getting SCRIPT1002: Syntax error
Do you see there a wrong part in the command?
Internet Explorer does support indexOf, but does not support arrow functions.
You can easily fix that using a regular function for the callback instead:
pairs = pre_final_pairs.filter(
function (elem, index) {
return pre_final_pairs.indexOf(elem) === index;
}
).join(' ');
I am using the underscore js library (http://underscorejs.org/#filter) for functionality in my app.
Everything works as expected in chrome. However when I run the same code in IE11 I get an js error in the console
SCRIPT1002: Syntax error
File: OptionSrv.js, Line: 197, Column: 62
When I clicked the file to bring me to the error the cursor is placed on the => - is this a red herring or should there be another way of doing this which works in both chrome and IE?
Note if I comment out the line in IE I don't get the console error however this obviously isn't the fix that I need
var group = myOptions.filter(g => g.options.indexOf(option.OptionCode) > -1);
Internet Explorer 11 does not support arrow functions.
That's the g => g.options.indexOf(option.OptionCode) > -1 part of your code.
You can use a normal anonymous (or named) function instead here, and it should work fine:
var group = myOptions.filter(function(g) {
g.options.indexOf(option.OptionCode) > -1);
});
IE11 does not support ES6 syntax. If you want to write ES6 syntax like Arrow functions, you can run your code through a transpiler like Babel.
If you like your client-side code to be compatible with older browsers and you don't care about new syntax, simply use ES5 syntax :)
This snippet of code...
sourcerow = $('#' + recordid);
item = sourcerow.find('td');
item.eq(1).text(itwcode);
Works fine in Firefox and Chrome.
But today I discovered that IE throws an error on this line - item.eq(1).text(itwcode);
The error is Object does not support this property or method 'eq'
I thought maybe 'item' was not properly being recognised as a jquery element so I tried this..
sourcerow = $('#' + recordid);
item = $(sourcerow.find('td'));
item.eq(1).text(itwcode);
Same error, so I tried this...
sourcerow = $('#' + recordid);
item = sourcerow.find('td');
$(item).eq(1).text(itwcode);
But now IE throws an error from inside the jquery library...
Invalid calling object jquery-1.9.1.min.js line 3 character 7849
Is there a way to solve or get around this error?
EDIT: As suggested by mikakun in the comments, I changed the name of the variable from 'item' to something else ('rowitem') and the code now works in IE. It's odd though because item is not a reserved word, and it worked fine in other browsers.
EDIT 2 Alternatively - leaving the name as 'item' but adding the 'var' keyword also fixed the code. item is used in another scope (but in a very similar way so same type)
In a practical sense, and if you use compilation for your project, you might consider to add at the top of your entry point
import 'core-js'
At the moment core-js polyfill library is the easiest way to make Cross Browser Support
This one really puzzles me, as the code looks completely harmless.
IE8 halts script execution with a message:
Not implemented. map.js line:66 char:5
Here is a snip from the code:
63 if(data.map[x] !== undefined && data.map[x][y] !== undefined) {
64
65 left = (x - data.dim.x_min)*32 + 30;
66 top = (data.dim.y_max - y)*32 + 30;
67
68 /* do stuff */
XX }
debug info: x:263 data.dim.x_min:263 y:172 data.dim.y_max:174
Data is object returned from JQuery Ajax call. This works in Firefox 3.0 and 3.5, safari 4.0.2 and I've only found this error when viewing the page in IE8. Forcing IE8 into IE7 mode does not make the error go away.
I don't have IE7 to debug with, but I got a tester saying that it doesn't work in IE7 either.
The variable 'top' used in the code is an object of type DispHTMLWindow2 (outermost window object) and already in use by the browsers and that is causing the conflict, as that object cant be the target of the assignment operation. It seems that Firefox and Safari ignore this, while IE does not allow scripts to overwrite this.
Solutions for this:
1) Declare top you are using as local variable to define it's scope where it is used.
2) Rename the variable to something that doesn't conflict with this predefined global.
Description of other variable names you shouldn't use
IE 8 has a great javascript debugger. You might want to add a breakpoint somewhere before the error and step through the code to see if something is strange with the data. IE8 is picky with trailing commas in lists which might be why you only get the error in it. You can pull the debugger up with F12, click Script and choose start debugging. You can add a break point by clicking on the margin where the line numbers are.