D3: "Invalid argument" error using d3.js in IE9 - javascript

I am trying to to get maps working in IE9 using d3.v3.js, world-110m.json and topojson.v1.js (I'm also using jQuery 10.1 so that is loaded too). It works fine in FF and Chrome but, as I am aware, IE 8 and below do not have native SVG support and therefore cannot be supported without workarounds.
Unfortunately, IE9 does not seem to work either. An error is thrown in the IE 9 console:
SCRIPT87: Invalid argument.
d3.v3.js, line 726 character 4
d3_selectionPrototype.insert = function(name, before) {
name = d3_selection_creator(name);
before = d3_selection_selector(before);
return this.select(function() {
return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments));
});
};
Line 726 is "return this.insertBefore" etc. Any ideas what's going on and how to resolve?

IE9 doesn't implement insertBefore quite the same way as other browsers. More detail in the answer to this question I suspect that in your case the second argument is null.

Related

Underscore js syntax error in IE 11

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 :)

String contains not working in IE

I am trying to use contains to find out if a phrase appears within a string
The code below works fine in FF and Chrome, however IE8-10 return an error.
SCRIPT438: Object doesn't support property or method 'contains'
var str = "This is a string";
if(str.contains("string")){
alert('Yes'};
}
Not sure why IE is throwing a error so any help would be much appreciated.
The .contains() function is an ES2015 feature that older Internet Explorer versions don't support.
The MDN page has a polyfill:
if ( !String.prototype.contains ) {
String.prototype.contains = function() {
return String.prototype.indexOf.apply( this, arguments ) !== -1;
};
}
A general guide for questions like this: type MDN something into the Google search box. If you don't find a result, then "something" probably doesn't exist in the JavaScript universe. If you do, then there's a pretty good chance that you'll find the answer you seek there.

Unexpected call to method or property access in IE 7

For work, I need to get our site working in IE7. Because, as we all know, the corporate world can't upgrade.
I am using IE8's IE7 emulation mode to test the site, and using IE8's wonderful debugger has been a nightmare.
My most recent problem is the following error:
Unexpected call to method or property access. jquery.js, line 113 character 460
I've put console.log commands on every line of my function, and figured out the line that's causing the error.
var $loading = $('<span/>').addClass('span-icon icon-ajax-loader').html('Loading...');
This line works fine in Firefox and Chrome. Oh, and it works fine when entering it into IE8's JavaScript console.
Why would this line give Unexpected call to method or property access? I think the call to the method or property was totally expected.
UPDATE: As per #Pointy's suggestion I broke that line into 3 lines.
var $loading = $('<span/>');
$loading.addClass('span-icon icon-ajax-loader');
$loading.html('Loading...');
Now I'm getting the error on this call $loading.html('Loading...');. Again, if I paste this code into IE8's developer tools and run it, it works fine.
Where are you injecting the content? Have you looked at this question and answer?
Javascript IE error: unexpected call to method or property access
Thanks to #daniellmb and #yoavmatchulsky for helping me fix this issue.
There are actually 3 separate solutions.
Use .text() instead of .html().
var $loading = $('<span/>').addClass('span-icon icon-ajax-loader').text('Loading...');
Wrap the .html() in span tags.
var $loading = $('<span/>').addClass('span-icon icon-ajax-loader').html('<span>Loading...</span>');
Or replace $('<span/>') with $('<span></span>').
var $loading = $('<span></span>').addClass('span-icon icon-ajax-loader').html('Loading...');

Does IE7 not fully support javascript's insertBefore method?

I have the following code which works perfect in Chrome, IE8, and FF. However, I get an error when I'm testing it with IE7. Does anyone have a clue what's happening here?
function do_replace(s, p1,p2,p3,child_node,syn_text) {
reg = new RegExp('[h\|H][1-7]');
if(p1.length>0){ //this might not be necessary
//create textnode
var text_node = document.createTextNode(p1);
child_node.parentNode.insertBefore(text_node,child_node); //errors out here in IE7
}
The code errors out at the last line- IE7 give an "htmlfile: Invalid argument." error when I look at the code through a debugger. child_node, parentNode, and text_node appear to be formed identical to Firefox and Chrome when running this script.
Any ideas? Or does IE7 just not support this method as well as other browsers?
Thanks
Rather than leave this problem unsolved, I figured out what was wrong with my code:
I was using an extensive frameset(yuck!!) and when I made the text_node = document.createTextNode() call, I was not doing this in the frame that my application was in.
I fixed this by explicitly calling out the frame to create the object in:
var text_node = MainFrame.child_frame.WhySoManyFrames.document.createTextNode(p1);
After doing this, the insertBefore method works perfect!
Hopefully this helps anyone looking at this question- I know this took me a long time and lots of frustration to figure out!
JavaScript 'InsertBefore' function is supported by IE7. Remember that you have to use this function only when page is fully loaded!
Details

Javascript error in IE8: Not implemented

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.

Categories

Resources