Javascript 检测 Skype?
某些Javascript是否可以检测是否安装了Skype?
我问的原因是我想基于此更改链接的href:如果未安装Skype,则显示弹出窗口解释 Skype 是什么以及如何安装它,如果已安装,请将链接更改为 skype:my.contact.name?call
这样单击即可开始通话。 房地产问题意味着我宁愿只显示一个链接。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
感谢大家的回答:从seanb 和一些发布的链接和方法中,我能够想出一个适用于 IE 和 Firefox 的解决方案,所以我想我应该发布一个“完整”的答案。 这是一个方便的 jQuery 扩展!
jQuery 扩展
用法
HTML:
Javascript:
就是这样!
如果有人使用 Safari、Opera 或 Chrome,它只会让浏览器处理它。
编辑:重新调整了该函数,以便它仅在页面加载时执行检查,而不是每次加载页面时执行检查。
$.skype
函数现在将返回一个布尔值,告诉您是否检测到 Skype。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
Usage
HTML:
Javascript:
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.适用于 IE 和 Firefox,但不适用于 Chrome 或 Opera
Works in IE and Firefox, but not Chrome or Opera
依靠 nickf 可靠的检测方法,我只需将 Skype 用户名添加到数据属性(“data-skype”)并更改所有的 href 值>电话:链接(如果不支持 Skype)。 工作得非常好,如果禁用 Javascript,则具有正常 tel: 超链接的全局应用程序仍保持完好。
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.
IE 的 skype 插件会修改 DOM,因此您始终可以在某处有一个“虚拟”电话号码字段,并查找任何带有类名“skype_tb_injection”的注入“span”元素...
您正在寻找的是这样的:
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:
听起来你正在把自己编码到一个角落里..试图用 JS 检测 Skype,耗尽屏幕空间。
如果相反,“联系”链接将用户带到联系页面,其中包含您的“Skype:”链接和解释性的 Skype 下载内容,那么整个事情可能会更友好。 它比 JS 弹出窗口有用得多。
您可以添加一些首选项,例如“我有 Skype 不再显示此页面”复选框到此页面。 然后使用该首选项切换您的“联系”链接。
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.
不,通常不可能检测是否从网页安装了 Skype 或任何其他软件,除非应用程序执行某些特定操作来提供信息,例如修改 .Net 中的用户代理字符串,或者您有特殊的浏览器扩展,
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,
这不是 javascript 的安全策略想要的。
如果没有插件或其他第三方的东西,你永远不会得到这样的信息。 您只能获取操作系统上缺少插件的信息,而不能获取缺少软件的信息。
同时在 mac&linux&windows 上运行也应该是有问题的。
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.
您可以使用 W3C 标准,浏览器将确定安装哪个软件来管理呼叫:
You can use the W3C standard and the browser will determine which software is installed to manage calls:
我刚刚在我的 Fedora 12 上测试,Linux 平台上使用的 firefox 或其他浏览器无法工作 Skype 协议。
即使安装了 Linux Skype。
注意:以上参考适用于 Windows 平台
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
所有浏览器插件都在名为
mimeTypes
的全局数组中注册其 mime 类型,可以通过导航器对象navigator.mimeTypes
访问该数组。因此您可以使用它来检查插件是否处于活动状态。 如果安装并禁用插件 - 不会为该禁用的插件注册任何 mime 类型。 如果插件已安装并处于活动状态 - 他在
navigator.mimeTypes
中有一个 mime 类型记录使用 jQuery 的一些代码实现:
所以这样:
$.checkPlugin("skype");
返回true
如果 Skype click2call 插件已安装并处于活动状态。 如果没有活动插件或未安装插件,则为false
。实际上需要在另一个全局数组 -
navigator.plugins
中搜索,但所有活动插件的记录都在navigator.mimeTypes
中,这更容易一些。All browser plugins registering their mime-types in global array named
mimeTypes
, that can be accessed via navigator objectnavigator.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:
So this:
$.checkPlugin("skype");
returnstrue
if skype click2call plugin is installed and active. Andfalse
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 innavigator.mimeTypes
, and this is a bit easier.编写一个签名的 Java 小程序可能是值得的。 这样您至少可以访问操作系统并确定 Skype 是否以这种方式安装。 否则,正如所注意到的,Javascript 不允许这种事情(如果允许的话,你的计算机就已经受到损害了)。
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).