How to check for FormData using Modernizr and YesNope Javascript
Asked Answered
R

2

5

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

<script>
yepnope({  
  test : what.to.check,  
  yep  : 'normal.js',  
  nope : 'flashupload.js'  
});      
</script>
Rodriguez answered 3/5, 2012 at 15:28 Comment(0)
H
9

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

Hypophosphate answered 3/5, 2012 at 15:31 Comment(0)
T
4

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

Modernizr.addTest('formdata', ('FormData' in window));
Toil answered 21/11, 2014 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.