简体   繁体   English

是否可以使用javascript测试用户的浏览器/操作系统是否支持给定类型的链接?

[英]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.

相关问题 JavaScript可以检测用户的浏览器是否支持gzip吗? - Can JavaScript detect if the user's browser supports gzip? 如何测试当前浏览器是否支持给定的 tagName - How to test if current browser supports a given tagName 是否可以通过 JavaScript 中的浏览器确定操作系统中设置的用户区域设置的**国家/地区**? - Is it possible to determine the user locale's **country** as set in the OS from the browser in JavaScript? 有什么方法可以测试使用网络技术的移动浏览器是否支持Flash? - Is there any how I can test whether a mobile browser supports flash using web technology? 是否可以在浏览器中使用javascript对用户的系统进行基准测试 - Is it possible to benchmark a user's system with javascript in the browser 确定浏览器是否在iFrame中支持javascript? - Determine whether browser supports javascript from within iFrame? 如何在浏览器的 JavaScript 中检查服务器是否支持 HTTP/2 - How to check whether server supports HTTP/2 in JavaScript on browser 使用Javascript检测浏览器是否支持Web开放字体格式(Woff) - Detecting with Javascript whether a Browser supports Web Open Font Format (Woff) or not 确定浏览器是否支持打印 - Determine whether browser supports printing 如何测试浏览器是否接受JavaScript的Cookie? - How to test whether a browser accepts cookies with JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM