views:

72

answers:

2

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?

+1  A: 

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.

Jonathan Sampson
But unfortunately, it looks like this would popup the disabled alert for both users that do support mailto and those that don't.
WIlliam Jones
@williamjones: It wasn't mean to be a copy/paste solution. Only a demonstrating of attaching logic to mailto links. The real solution is to create your own contact page, and provide a small form that can be submitted through the site, rather than a local email client.
Jonathan Sampson
+1  A: 

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

David Dorward
+1 Good information.
Jonathan Sampson
I've tried it on IE and Firefox on a computer without mailto: configured. On IE8, it pops up a message, "Could not perform this operation because the default mail client is not properly installed." Not too helpful for a user who only has webmail. On Firefox clicking the link seems to just do nothing, with no feedback as to what the problem is.
WIlliam Jones