Determine whether a URI scheme is enabled

Discussion in 'Javascript' started by Chris Davies, Oct 3, 2007.

  1. Chris Davies

    Chris Davies Guest

    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.

    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
     
    Chris Davies, Oct 3, 2007
    #1
    1. Advertising

  2. Chris Davies

    David Mark Guest

    On Oct 3, 9:11 am, Chris Davies <> wrote:
    > 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.
    >
    > 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.
     
    David Mark, Oct 3, 2007
    #2
    1. Advertising

  3. Chris Davies wrote:
    > 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.
    >
    > 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
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Oct 4, 2007
    #3
  4. Chris Davies

    Chris Davies Guest

    Chris Davies wrote:
    > 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 <> wrote:
    > 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
     
    Chris Davies, Oct 5, 2007
    #4
  5. Chris Davies wrote:
    > Chris Davies wrote:
    >> 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 <> wrote:
    >> You can do something along

    >


    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
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
     
    Thomas 'PointedEars' Lahn, Oct 5, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Harris
    Replies:
    0
    Views:
    6,379
    Simon Harris
    May 10, 2005
  2. Stanimir Stamenkov
    Replies:
    1
    Views:
    2,474
    Stanimir Stamenkov
    Aug 17, 2005
  3. Pavel
    Replies:
    2
    Views:
    1,650
    Peter Flynn
    Aug 4, 2004
  4. etheriau
    Replies:
    1
    Views:
    667
    Pavel
    Aug 23, 2004
  5. Jerry Fleming

    How to open a file designated with file uri scheme

    Jerry Fleming, Dec 1, 2010, in forum: C Programming
    Replies:
    3
    Views:
    469
    Nobody
    Dec 2, 2010
Loading...

Share This Page