[英]Is it possible to test whether a user's browser/OS supports a given type of link using javascript?
Is it possible to test whether a user's OS/browser supports a given url scheme using javascript (or anything else)? 是否可以使用javascript(或其他任何东西)测试用户的OS /浏览器是否支持给定的url方案?
For example, mailto: isn't setup on most user's computer that only use webmail. 例如,在仅使用Webmail的大多数用户的计算机上未设置mailto:。 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链接并弹出比浏览器错误消息更具描述性的解释?
In the general case — I don't think so. 在一般情况下 - 我不这么认为。
In the specific case of mailto: — no. 在mailto的具体情况: - 没有。
To solve the problem you need to describe you need to know if the user has a configured email client, not if the browser supports mailto:. 要解决您需要描述的问题,您需要知道用户是否具有已配置的电子邮件客户端,而不是浏览器是否支持mailto:。 Most browsers support mailto:, and if the user doesn't have a configured client — it still 'works' (by starting the email client and prompting the user to configure it).
大多数浏览器都支持mailto:,如果用户没有配置的客户端 - 它仍然“有效”(通过启动电子邮件客户端并提示用户进行配置)。
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链接并弹出比浏览器错误消息更具描述性的解释?
I don't know that you can determine whether a browser supports mailto: links. 我不知道您可以确定浏览器是否支持mailto:links。 But as for attaching logic to mailto links, you could cycle through the links on the page, and test their
href
value. 但是对于将逻辑附加到mailto链接,您可以循环浏览页面上的链接,并测试它们的
href
值。 If it begins with "mailto:" you could attach a popup upon clicking it. 如果以“mailto:”开头,则可以在单击时附加弹出窗口。
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. 我能想到的唯一真正的解决方案是托管您自己的联系页面,提供用户可以提交的小表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.