jonathantneal / flexibility

A JavaScript polyfill for Flexbox
https://jonathantneal.github.io/flexibility/
MIT License
4.33k stars 479 forks source link

Uncaught TypeError: document.attachEvent is not a function #55

Closed hendrathings closed 8 years ago

hendrathings commented 8 years ago

I use this plugin and get this error Uncaught TypeError: document.attachEvent is not a function in chrome and edge browser. Does any plugin missing here?

pecktron2000 commented 8 years ago

I am getting this error message as well in Chrome. in Firefox, I get the following message:

TypeError: document.attachEvent is not a function ...n!1}},(!flexibility.detect()||t()<=9)&&document.attachEvent("onreadystatechange"...

mastastealth commented 8 years ago

This is an IE-only function it seems: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/attachEvent

hendrathings commented 8 years ago

@mastastealth have you try it in ie? version 8 - edge? is it work for you?

wyattdanger commented 8 years ago

There's no need to load this file in non-IE browsers

The issue is in this line here https://github.com/10up/flexibility/blob/master/lib/detect.js#L21 because ieVersion() returns false in non-IE browsers, and false <= 9 evaluates to true

ajsharp commented 8 years ago

@wyattdanger It'd be helpful to have this noted very strongly in the readme.

thehenster commented 8 years ago

The fix is good to have :+1:

It would be nice to have a conditional comment version in the readme. It's a bandwith/connection saver.

<!--[if lte IE 9]>
  <script src="flexibility.js"></script>
<![endif]-->
Dan503 commented 8 years ago

The conditional comment needs to be

<!--[if lt IE 10]>
  <script src="flexibility.js"></script>
<![endif]-->

Flexbox doesn't work in IE9 so it needs to be loaded there as well. Or it could even just be this since conditional comments don't work in IE 10

<!--[if IE]>
  <script src="flexibility.js"></script>
<![endif]-->
mastastealth commented 8 years ago

@Dan503 The original conditional works as well. if lte IE 9 means "less than or EQUAL to IE9" which is the same as if lt IE 10

Dan503 commented 8 years ago

Oh I didn't spot the "e". Ok yeah, yours works as well and is probably the better one to go with.

jonathantneal commented 8 years ago

There are no events firing in v2, so this should no longer be an issue.