Skip to content

Instantly share code, notes, and snippets.

@gkralik
Last active August 29, 2015 14:26
Show Gist options
  • Save gkralik/78da908b6b2a0cbb4356 to your computer and use it in GitHub Desktop.
Save gkralik/78da908b6b2a0cbb4356 to your computer and use it in GitHub Desktop.
Detect ClickOnce support of browser
Detect if ClickOnce is (or rather: might be) supported by the browser.
This is partly based on https://gist.github.com/adunkman/2371101.
If the userAgent string does not contain a .NET feature hint,
we settle for everything that looks like an IE, because .NET
is installed nearly everywhere nowadays.
It might also be a good idea to check for the X-ClickOnceSupport
header on the server side.
(function () {
var isMimeSupported = function (desiredMime) {
var mimes = window.navigator.mimeTypes;
for (var i = 0; i < mimes.length; i++) {
if (mimes[i].type == desiredMime) {
return true;
}
}
return false;
};
var isClickOnceSupported = function () {
var userAgent = window.navigator.userAgent.toLowerCase(),
hasDotNetFeatureHint = userAgent.indexOf('.NET CLR') >= 0,
looksLikeIE = userAgent.indexOf('msie') >= 0,
looksLikeTrident = userAgent.indexOf('trident') >= 0,
looksLikeEdge = userAgent.indexOf('edge') >= 0;
return hasDotNetFeatureHint || looksLikeIE
|| looksLikeTrident || looksLikeEdge
|| isMimeSupported('application/x-ms-application');
};
window.hasClickOnceSupport = isClickOnceSupported();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment