Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to detect Skype?

Tags:

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.

like image 381
nickf Avatar asked Dec 11 '08 03:12

nickf


2 Answers

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!

The 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;     } }); 

Usage

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.

like image 60
nickf Avatar answered Sep 16 '22 14:09

nickf


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; } 
like image 26
some Avatar answered Sep 18 '22 14:09

some