Skip to content

Instantly share code, notes, and snippets.

@adunkman
Created April 12, 2012 21:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adunkman/2371101 to your computer and use it in GitHub Desktop.
Save adunkman/2371101 to your computer and use it in GitHub Desktop.
Detect ClickOnce support
This detects the presence of ClickOnce in IE, Chrome (with extension), and
Firefox (with extension).
It doesn't work if Firefox is using Microsoft's .NET Framework Assistant when
adding .NET information to the User Agent string is turned off (the default
setting as of late). I personally worked around this by using server logic to
detect if the X-ClickOnceSupport header was set.
(function () {
// Detect if ClickOnce is supported by the browser.
// Roughly based on http://stackoverflow.com/a/4653175/117402
var hasMimeSupport = function (desiredMime) {
var mimes = window.navigator.mimeTypes,
hasSupport = false;
for (var i = 0; i < mimes.length; i++) {
var mime = mimes[i];
if (mime.type == desiredMime) {
hasSupport = true;
}
}
return hasSupport;
};
var sniffForClickOnce = function () {
var userAgent = window.navigator.userAgent.toUpperCase(),
hasNativeDotNet = userAgent.indexOf('.NET CLR 3.5') >= 0;
return hasNativeDotNet || hasMimeSupport("application/x-ms-application");
};
window.clickOnce = sniffForClickOnce();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment