1

Hello I have been working in AngualarJS and using File UPload control which works completely fine. Now I have used FileAPI to make that working in IE8/9.

But now I want to detect if the browser support FormData because I want to restrict only one file at a time.But as I am using FileAPI the method window.FormData === undefined is not working as because of that I get something like this in IE8 :

function(){return{append:function(a,b,c){this.data.push({key:a,val:b,name:c})},data:[],__isShim:!0}} 

How can I detect if the browser support FormData ?

Moiz
  • 2,409
  • 5
  • 27
  • 50

1 Answers1

2

Since you are using a shim and since your shim seems to return an object with a __isShim property with a value of true, you could check it like this:

var isFormDataSupported = window.FormData && !(new window.FormData()).__isShim;

Alternatively, you could check it before including your shim:

<script type="text/javascript">
    var isFormDataSupported = !!window.FormData;
</script>
<script src="src/to/your/shim.js"></script>
gkalpak
  • 47,844
  • 8
  • 105
  • 118
  • Thanks for the solution, but JSLINT throws this error : JSLint : Unexpected dangling '_' in '__isShim' – Moiz Jun 04 '14 at 07:29
  • **[This "thread"](http://stackoverflow.com/questions/12640173/js-lint-unexpected-dangling-in-fngettrnodes)** explains why and **[that one](http://stackoverflow.com/questions/3039587/jslint-reports-unexpected-dangling-character-in-an-underscore-prefixed-variabl)** how to get rid of it. It is just a warning, not an actual problem. Alternatively, you could check `FormData` **before** loading the shim. – gkalpak Jun 04 '14 at 07:34
  • what if I use : if ($window.FormData.toString().indexOf('__isShim') !== -1) { – Moiz Jun 04 '14 at 08:05
  • It would work as well (although note that `!==-1` means `isNotSupported`). – gkalpak Jun 04 '14 at 08:15