Javascript to detect Skype?

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.

Answers:

Answer

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.

Answer

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;
}
Answer

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');
    }
});
Answer

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>
Answer

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.

Answer

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,

Answer

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.

Answer

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>
Answer

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

Answer

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.

Answer

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).

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.