27

If XHR2 is supported with file-upload capabilites, my application needs to do different preparation. What is a safe way to check if these capabilities are supported. Is it sufficient, for example, to just check an XMLHttpRequest (or MS equivalents) for the upload property? like...

var xhr = new XMLHttpRequest();
if (typeof xhr.upload !== "undefined") {
  do nice stuff
}
else {
  do oldschool stuff
}

Or is this not safe?

rewolf
  • 5,561
  • 4
  • 40
  • 51

1 Answers1

50
if (new XMLHttpRequest().upload) {
  // welcome home!
} else {
  // not supported
}
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Pono
  • 11,298
  • 9
  • 53
  • 70