getElementsByClassName() doesn’t work in old Internet Explorers like IE6, IE7, IE8

IE6, Netscape 6+, Firefox, and Opera 7+ copy the following script in your page: document.getElementsByClassName = function(cl) { var retnode = []; var elem = this.getElementsByTagName(‘*’); for (var i = 0; i < elem.length; i++) { if((‘ ‘ + elem[i].className + ‘ ‘).indexOf(‘ ‘ + cl + ‘ ‘) > -1) retnode.push(elem[i]); } return retnode; … Read more

addEventListener not working in IE8

Try: if (_checkbox.addEventListener) { _checkbox.addEventListener(“click”, setCheckedValues, false); } else { _checkbox.attachEvent(“onclick”, setCheckedValues); } Update:: For Internet Explorer versions prior to IE9, attachEvent method should be used to register the specified listener to the EventTarget it is called on, for others addEventListener should be used.

IE8 issue with Twitter Bootstrap 3

You got your CSS from CDN (bootstrapcdn.com) respond.js only works for local files. So try your website on IE8 with a local copy of bootstrap.css. Or read: CDN/X-Domain Setup Note See also: https://github.com/scottjehl/Respond/pull/206 Update: Please read: http://getbootstrap.com/getting-started/#support In addition, Internet Explorer 8 requires the use of respond.js to enable media query support. See also: https://github.com/scottjehl/Respond … Read more

Override intranet compatibility mode IE8

It is possible to override the compatibility mode in intranet. For IIS, just add the below code to the web.config. Worked for me with IE9. <system.webServer> <httpProtocol> <customHeaders> <clear /> <add name=”X-UA-Compatible” value=”IE=edge” /> </customHeaders> </httpProtocol> </system.webServer> Equivalent for Apache: Header set X-UA-Compatible: IE=Edge And for nginx: add_header “X-UA-Compatible” “IE=Edge”; And for express.js: res.set(‘X-UA-Compatible’, ‘IE=Edge’)

javascript document.getElementsByClassName compatibility with IE

It’s not a method of document: function getElementsByClassName(node, classname) { var a = []; var re = new RegExp(‘(^| )’+classname+'( |$)’); var els = node.getElementsByTagName(“*”); for(var i=0,j=els.length; i<j; i++) if(re.test(els[i].className))a.push(els[i]); return a; } tabs = getElementsByClassName(document.body,’tab’); // no document

Why doesn’t indexOf work on an array IE8?

Versions of IE before IE9 don’t have an .indexOf() function for Array, to define the exact spec version, run this before trying to use it: if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); … Read more

‘console’ is undefined error for Internet Explorer

Try if (!window.console) console = … An undefined variable cannot be referred directly. However, all global variables are attributes of the same name of the global context (window in case of browsers), and accessing an undefined attribute is fine. Or use if (typeof console === ‘undefined’) console = … if you want to avoid the … Read more

JS li tag onclick not working on IE8

IE8 and earlier don’t have addEventListener, but they do have its non-standard predecessor, attachEvent. They’re not quite the same. Here’s a “hook this event” function that uses what’s available: var hookEvent = (function() { var div; // The function we use on standard-compliant browsers function standardHookEvent(element, eventName, handler) { element.addEventListener(eventName, handler, false); return element; } … Read more