21

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.

nickf
  • 537,072
  • 198
  • 649
  • 721

11 Answers11

31

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.

nickf
  • 537,072
  • 198
  • 649
  • 721
  • 1
    the above code produces this error in console(chrome): Uncaught TypeError: Cannot read property 'safari' of undefined – domii Nov 10 '15 at 20:32
  • 1
    @domii I guess jQuery removed the `.browser` object some time in the last 7 years... – nickf Nov 12 '15 at 17:41
7

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;
}
some
  • 48,070
  • 14
  • 77
  • 93
4

Leaning on nickf's reliable detection methods, I just add the skype username to a data attribute ("data-skype") and change the href values for all tel: links if skype is not supported. Works really well, global application with normal tel: hyperlinks remaining in tact if Javascript is disabled.

<!-- the links -->
<a href="tel:+15035551212" data-skype="yourskypeusername" title="Call">Call</a>

/* the javascript*/
function hasSkype() {
    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;
        }
    }
    return false;
}

$('a[href^="tel:"]').each(function() {
    if(hasSkype()) {
        // if Skype is available, update the link to use Skype
        $(this).attr('href','skype:'+$(this).attr('data-skype')+'?call');
    }
});
2

The skype plugin for IE modifies the DOM so you can always have a 'dummy' phone number field somewhere and look out for any injected 'span' elements with classname 'skype_tb_injection'...

What you're looking for is something like this:

<SPAN onmouseup=".." class="skype_tb_injection" onmousedown="..." id="softomate_highlight_0" onmouseover="..." title="Call this phone number in Thailand with Skype: +66812341234" onclick="..." onmouseout="..." durex="0" context="+66 8 1234 1234" IamRTL="0">
  <SPAN class="skype_tb_nop">&nbsp;</SPAN>
  <SPAN onmouseup="..." class="skype_tb_imgA_flex" onmousedown="..." id="skype_tb_droppart_0" onmouseover="..." title="Skype actions" style="..." onclick="..." onmouseout="...">
    &nbsp;&nbsp;
    <SPAN class="skype_tb_nop">&nbsp;</SPAN>
    <SPAN class="skype_tb_imgFlag" id="skype_tb_img_f0" style="...">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>
    &nbsp;
    <SPAN class="skype_tb_nop">&nbsp;</SPAN>
  </SPAN>
  <SPAN class="skype_tb_imgS" id="skype_tb_img_s0" style="...">&nbsp;</SPAN>
  <SPAN class="skype_tb_injectionIn" id="skype_tb_text0" style="...">
    <SPAN class="skype_tb_innerText" id="skype_tb_innerText0"> +6...</SPAN>
  </SPAN>
  <SPAN class="skype_tb_imgR" id="skype_tb_img_r0" style="...">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <SPAN class="skype_tb_nop">&nbsp;</SPAN>
  </SPAN>
</SPAN>
KristoferA
  • 12,287
  • 1
  • 40
  • 62
1

sounds like you're coding yourself into a bit of a corner there.. trying to detect skype with JS, running out of screen real estate.

the whole thing might be friendlier if instead, the "Contact" link takes the user to a contact page, with your "skype:" links and your explanatory skype-download content. it'll be a bunch more useful than a JS popup.

you could add some prefs, like an "i have skype don't show this page again" checkbox to this page. Then use that pref to toggle your "Contact" link.

nailitdown
  • 7,868
  • 11
  • 36
  • 37
0

You can use the W3C standard and the browser will determine which software is installed to manage calls:

<a href="callto:<phone_number>"><phone_number></a>
sth
  • 222,467
  • 53
  • 283
  • 367
gu.
  • 1
0

All browser plugins registering their mime-types in global array named mimeTypes, that can be accessed via navigator object navigator.mimeTypes.

So you can use this for check plugin active or not. If plugin installed and disabled — no any mime-type will be registred for that disabled plugin. If plugin installed and active — he has a mime-type record in navigator.mimeTypes

Some code implementation using jQuery:

jQuery.extend({checkPlugin: function(mimetype_substr) {
    for (var i = 0; i < navigator.mimeTypes.length; i++) {
        if (navigator.mimeTypes[i]['type'].toLowerCase().indexOf(mimetype_substr) >= 0) {
                console.log("Gotcha! Here it is: "+navigator.mimeTypes[i]['type']);
                return true;
        }
    }
    return false;
}});

So this: $.checkPlugin("skype"); returns true if skype click2call plugin is installed and active. And false if there is no active plugin or plugin are not installed.

Actually need to search within another global array — navigator.plugins, but all active plugins have their records in navigator.mimeTypes, and this is a bit easier.

0

I was just testing in my Fedora 12, Linux platform using firefox or other browser does not work skype protocol.

Even having linux skype installed.

N.B: Above references are good for Windows platform

0

No, it's not generally possible to detect if skype or any other software is installed from a web page unless the app does something specific to make the information available like modify the user agent string a la .Net or you have a special browser extension,

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Well, the question as I see it is whether there's anything able to cope with 'skype:' URLs. Which Skype will do, if it's installed. Which makes it relevant and possible. Still looking for a solution for Safari. – akauppi Jul 31 '10 at 08:07
0

That would not be what security policy of javascript wants.

Without a plugin or other third party stuff you never get such infos. You only can get informations of missing plugins but not missing software on your OS.

should also be problematic to get this working on mac&linux&windows at the same time.

berlindev
  • 1,753
  • 14
  • 22
-2

It might be worthwhile to write a signed java applet. That way you can at least get access to the OS and determine if Skype is installed that way. Otherwise, as noticed, Javascript doesnt allow that sort of thing (if it did, your computer would of been compromised already).

user45200
  • 3
  • 1
  • 2
    that's a bit of overkill for my purposes, really. thanks for the answer though. – nickf Dec 11 '08 at 05:36
  • Also, its extremely common to *not* have java applet support. ( amd64 linux is generally this way, unless you're one of the rarities running IcedTea, and skype *does* work on linux. ) – Kent Fredric Dec 11 '08 at 05:46
  • nickf - i suggest you read up on javascript some more. kent - yea a lot of things dont work for amd64 linux – user45200 Dec 12 '08 at 02:09