modernizr
Version:
Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.
29 lines (26 loc) • 667 B
JavaScript
define(function() {
/**
* http://mathiasbynens.be/notes/xhr-responsetype-json#comment-4
*
* @access private
* @function testXhrType
* @param {string} type - String name of the XHR type you want to detect
* @returns {boolean}
* @author Mathias Bynens
*/
/* istanbul ignore next */
var testXhrType = function(type) {
if (typeof XMLHttpRequest == 'undefined') {
return false;
}
var xhr = new XMLHttpRequest();
xhr.open('get', '/', true);
try {
xhr.responseType = type;
} catch (error) {
return false;
}
return 'response' in xhr && xhr.responseType == type;
};
return testXhrType;
});