Is it possible for some Javascript to detect whether Skype is installed or not?
The reason I ask is that I'd like to change a link's href based on that: if Skype isn't installed, show a popup explaining what Skype is and how to install it, if it is installed, change the link to skype:my.contact.name?call
so the click will start a call. Real estate issues means that I'd prefer to only have one link shown.
Thanks for the answers everyone: from the links and methods seanb and some posted, I was able to come up with a solution which works for IE and Firefox, so I thought I'd post a 'complete' answer. Here it is as a handy jQuery extension!
jQuery.extend({ skype : function(failureFunction) { var $ = jQuery; if ($.browser.safari || $.browser.opera) { return true; } else if ($.browser.msie) { try { if (new ActiveXObject("Skype.Detection")) return true; } catch(e) { } } else { if (typeof(navigator.mimeTypes["application/x-skype"]) == "object") { return true; } } $('a[href^="skype:"]').click(function() { failureFunction(); return false; }); return false; } });
HTML:
<a href="skype:your.skype.username?call">Call me</a> <a href="skype:your.skype.username?add">Add me</a>
Javascript:
jQuery(function($) { $.skype(function() { // this function gets called if they don't have skype. alert("Looks like you don't have skype. Bummer."); }); });
And that's it!
If someone using Safari, Opera or Chrome comes along, it'll just let the browser deal with it.
edit: rejigged the function so that it only performs the check when the page loads, not each time the page is loaded. The $.skype
function will now return a bool telling you if skype was detected or not.
Works in IE and Firefox, but not Chrome or Opera
function isSkypeInstalled(str) { try { /*@cc_on //The Microsoft way, thanks to the conditional comments only run in IE if (new ActiveXObject("Skype.Detection")) return true; @*/ //Tested for firefox on win if (navigator.mimeTypes["application/x-skype"]) return true; } catch(e){} return false; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With