是否可以使用javascript测试用户的浏览器/操作系统是否支持给定类型的链接? [英] Is it possible to test whether a user's browser/OS supports a given type of link using javascript?
问题描述
是否可以使用javascript(或其他任何东西)测试用户的OS /浏览器是否支持给定的url方案?
Is it possible to test whether a user's OS/browser supports a given url scheme using javascript (or anything else)?
例如,mailto:不是在大多数只使用网络邮件的用户计算机上进行设置。是否有可能以某种方式捕获尝试单击mailto链接并弹出比浏览器错误消息更具描述性的解释?
For example, mailto: isn't setup on most user's computer that only use webmail. Would it be possible to somehow catch attempts to click a mailto link and pop up a more descriptive explanation than the browser error message?
推荐答案
是否有可能以某种方式捕获尝试点击mailto链接并弹出比浏览器错误消息更具描述性的解释?
我不知道你可以确定浏览器是否支持mailto:links。但是,对于将逻辑附加到mailto链接,您可以循环浏览页面上的链接,并测试它们的 href
值。如果它以mailto:开头,你可以在点击它时附上一个弹出窗口。
I don't know that you can determine whether a browser supports mailto: links. But as for attaching logic to mailto links, you could cycle through the links on the page, and test their href
value. If it begins with "mailto:" you could attach a popup upon clicking it.
var maillinks = document.getElementsByTagName("a");
var (var i = 0; i < maillinks.length; i++) {
var currentlink = maillinks[i];
if (currentlink.href.substring(0,7) === "mailto:") {
alert("Sorry. These aren't allowed.");
return false;
}
}
我能想到的唯一真正的解决方案是托管您自己的联系页面,提供用户可以提交的小表单。
The only real solution I can think to this problem is to host your own contact page, providing a small form that the user can submit.
这篇关于是否可以使用javascript测试用户的浏览器/操作系统是否支持给定类型的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!