Determine whether a URI scheme is enabled

C

Chris Davies

I'm curious. I'd like to determine whether a particular URI scheme (the
"ftp:", ""http:" part) is available within the user's browser.

For example, consider this HTML snippet:

Telephone us on <a href="tel:+44113393xxxx">0113 393-xxxx</a>

I could extend the tag with an onClick handler that displayed an
alert() box (or similar), but ideally I'd like it only to do that if
the underlying URI scheme couldn't be handled by the user's browser.

Thanks,
Chris
 
D

David Mark

I'm curious. I'd like to determine whether a particular URI scheme (the
"ftp:", ""http:" part) is available within the user's browser.

For example, consider this HTML snippet:

Telephone us on <a href="tel:+44113393xxxx">0113 393-xxxx</a>

I could extend the tag with an onClick handler that displayed an
alert() box (or similar), but ideally I'd like it only to do that if
the underlying URI scheme couldn't be handled by the user's browser.

You are out of luck there.
 
T

Thomas 'PointedEars' Lahn

Chris said:
I'm curious. I'd like to determine whether a particular URI scheme (the
"ftp:", ""http:" part) is available within the user's browser.

I could extend the tag with an onClick handler that displayed an alert()
box (or similar), but ideally I'd like it only to do that if the underlying
URI scheme couldn't be handled by the user's browser.

You can do something along

function navigateTo(s)
{
try
{
window.location = s;
}
catch (e)
{
window.alert("Unsupported URI scheme: " + s.match(/^[^:]+/));
}

return false;
}

<a href="foo:bar" onclick="return navigateTo(this.href);">...</a>

But you can't suppress an error message displayed by the UA already.


PointedEars
 
C

Chris Davies

Chris said:
I'm curious. I'd like to determine whether a particular URI scheme (the
"ftp:", "news:", "http:" part) is available within the user's browser.

Thomas 'PointedEars' Lahn said:
You can do something along
function navigateTo(s)
{
try
{
window.location = s;
}
catch (e)
{
window.alert("Unsupported URI scheme: " + s.match(/^[^:]+/));
}

In FF the "No program for this URI scheme" error (paraphrased) can't be
caught like this, so sadly I'm no better off.

Thanks for the thought.
Chris
 
T

Thomas 'PointedEars' Lahn

Please read the FAQ on how to quote correctly in Usenet.
function navigateTo(s)
{
try
{
window.location = s;
}
catch (e)
{
window.alert("Unsupported URI scheme: " + s.match(/^[^:]+/));
}

In FF the "No program for this URI scheme" error (paraphrased) can't be
caught like this,

It can be considered a great advantage here to be capable of reading.

| But you can't suppress an error message displayed by the UA already.
so sadly I'm no better off.

As I said: you can't do this.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top