modernizr
Version:
Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.
41 lines (38 loc) • 1.2 kB
JavaScript
/*!
{
"name": "Custom protocol handler",
"property": "customprotocolhandler",
"authors": ["Ben Schwarz"],
"builderAliases": ["custom_protocol_handler"],
"notes": [{
"name": "WHATWG overview",
"href": "https://developers.whatwg.org/timers.html#custom-handlers"
},{
"name": "MDN documentation",
"href": "https://developer.mozilla.org/en-US/docs/Web/API/navigator.registerProtocolHandler"
}],
"warnings": [],
"polyfills": []
}
!*/
/* DOC
Detects support for the `window.registerProtocolHandler()` API to allow websites to register themselves as possible handlers for particular protocols.
*/
define(['Modernizr'], function(Modernizr) {
Modernizr.addTest('customprotocolhandler', function() {
// early bailout where it doesn't exist at all
if (!navigator.registerProtocolHandler) {
return false;
}
// registerProtocolHandler was stubbed in webkit for a while, and didn't
// actually do anything. We intentionally set it improperly to test for
// the proper sort of failure
try {
navigator.registerProtocolHandler('thisShouldFail');
}
catch (e) {
return e instanceof TypeError;
}
return false;
});
});