Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for FormData using Modernizr and YesNope Javascript

How do I check for FormData object using Modernizr and YepNope?

<script>
yepnope({  
  test : what.to.check,  
  yep  : 'normal.js',  
  nope : 'flashupload.js'  
});      
</script>
like image 587
beingalex Avatar asked May 03 '12 15:05

beingalex


2 Answers

I was looking for a Modernizer way to check FormData the other day and couldn't find one.

However, it's easy to do without Modernizer:

window.FormData // exists if it exists, undefined if it doesn't!

So:

yepnope({  
  test : "FormData" in window,
  yep  : 'normal.js',  
  nope : 'flashupload.js'  
});   

FWIW, MDC compatability for FormData says you'll be targeting:

  • Chrome 7+
  • Firefox 4.0
  • IE 10+
  • Safari 5+

... Opera support is unknown

like image 91
Matt Avatar answered Sep 22 '22 13:09

Matt


You can extend Modernizr with custom tests. Just throw this into the end of your Modernizr file:

Modernizr.addTest('formdata', ('FormData' in window));
like image 28
Josh Avatar answered Sep 23 '22 13:09

Josh