用于检测Skype的Javascript? [英] Javascript to detect Skype?

查看:118
本文介绍了用于检测Skype的Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些Javascript是否可以检测是否安装了Skype?

我问的原因是我想要根据以下内容更改链接的href:如果未安装Skype,请显示一个弹出窗口,说明Skype是什么以及如何安装它,如果已安装,请将链接更改为 skype:my.contact。 name?call 所以点击将开始通话。房地产问题意味着我更愿意只显示一个链接。

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.

推荐答案

感谢大家的答案:来自链接和方法seanb和一些发布,我能够提出一个适用于IE和Firefox的解决方案,所以我想我会发布一个'完整'的答案。这是一个方便的jQuery扩展!

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:

Usage

HTML:

<a href="skype:your.skype.username?call">Call me</a>
<a href="skype:your.skype.username?add">Add me</a>

Javascript:

Javascript:

jQuery(function($) {
    $.skype(function() {
        // this function gets called if they don't have skype.
        alert("Looks like you don't have skype. Bummer.");
    });
});

就是这样!

如果有人使用Safari,Opera或Chrome时,只需让浏览器处理它。

If someone using Safari, Opera or Chrome comes along, it'll just let the browser deal with it.

编辑:重新调整功能以便它只执行检查页面加载时,而不是每次加载页面时。 $。skype 函数现在将返回一个bool,告诉你是否检测到skype

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.

这篇关于用于检测Skype的Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆