Javascript to detect Skype?
Asked Answered
E

11

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.

Equiponderate answered 11/12, 2008 at 3:49 Comment(0)
E
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.

Equiponderate answered 11/12, 2008 at 6:15 Comment(2)
the above code produces this error in console(chrome): Uncaught TypeError: Cannot read property 'safari' of undefinedGeter
@Geter I guess jQuery removed the .browser object some time in the last 7 years...Equiponderate
E
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;
}
Ethyne answered 11/12, 2008 at 4:7 Comment(0)
C
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');
    }
});
Castara answered 7/6, 2012 at 16:22 Comment(0)
H
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>
Handwoven answered 11/12, 2008 at 4:10 Comment(0)
S
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.

Subpoena answered 11/12, 2008 at 4:41 Comment(0)
T
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,

Transmit answered 11/12, 2008 at 3:59 Comment(1)
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.Torrell
G
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.

Gahan answered 11/12, 2008 at 4:5 Comment(0)
A
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>
Alodi answered 19/2, 2010 at 10:0 Comment(1)
Well, this does not work if we want a Skype call instead of a usual numbered one.Torrell
P
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

Pathetic answered 24/7, 2010 at 18:50 Comment(0)
P
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.

Porcine answered 28/8, 2014 at 6:31 Comment(0)
K
-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).

Keyek answered 11/12, 2008 at 4:29 Comment(3)
that's a bit of overkill for my purposes, really. thanks for the answer though.Equiponderate
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. )Asphaltite
nickf - i suggest you read up on javascript some more. kent - yea a lot of things dont work for amd64 linuxKeyek

© 2022 - 2024 — McMap. All rights reserved.