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

发布于 2024-08-21 17:35:59 字数 149 浏览 4 评论 0原文

是否可以使用 javascript(或其他任何东西)测试用户的操作系统/浏览器是否支持给定的 url 方案?

例如,大多数仅使用网络邮件的用户计算机上未设置 mailto:。是否有可能以某种方式捕获单击 mailto 链接的尝试并弹出比浏览器错误消息更具描述性的解释?

Is it possible to test whether a user's OS/browser supports a given url scheme using javascript (or anything else)?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静待花开 2024-08-28 17:35:59

在一般情况下——我不这么认为。

在 mailto 的具体情况下: — 不。

要解决您需要描述的问题,您需要知道用户是否配置了电子邮件客户端,而不是浏览器是否支持 mailto:。大多数浏览器支持 mailto:,并且如果用户没有配置客户端 — 它仍然“有效”(通过启动电子邮件客户端并提示用户配置它)。

In the general case — I don't think so.

In the specific case of mailto: — no.

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:. 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).

陪我终i 2024-08-28 17:35:59

是否有可能以某种方式捕获点击 mailto 链接的尝试并弹出比浏览器错误消息更具描述性的解释?

我不知道您可以确定浏览器是否支持 mailto: 链接。但对于将逻辑附加到 mailto 链接,您可以循环浏览页面上的链接,并测试它们的 href 值。如果它以“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;
  }
}

我能想到的解决这个问题的唯一真正的解决方案是托管您自己的联系页面,提供用户可以提交的小表单。

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?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文