discover javascript capabilities from server side

Discussion in 'ASP .Net' started by Jeremy Chapman, Jun 14, 2006.

  1. Is there any way via server side code to determine if the browser supports
    javascript?
     
    Jeremy Chapman, Jun 14, 2006
    #1
    1. Advertising

  2. > Is there any way via server side code to determine if the browser supports
    > javascript?


    You can tell if the browser supports JS using
    Page.Request.Browser.JavaScript. If you want to see if it's actually
    *enabled*, it is a little harder; you could check if it's supported and
    if so send a page containing a Javascript to redirect to a
    Javascript-capable version of your page, which clearly would then only
    be reached if script were actually enabled.

    An example : http://www.15seconds.com/issue/030303.htm

    -- PH
     
    Paul Henderson, Jun 14, 2006
    #2
    1. Advertising

  3. Genius! Thanks.

    "Paul Henderson" <> wrote in message
    news:...
    >> Is there any way via server side code to determine if the browser
    >> supports
    >> javascript?

    >
    > You can tell if the browser supports JS using
    > Page.Request.Browser.JavaScript. If you want to see if it's actually
    > *enabled*, it is a little harder; you could check if it's supported and
    > if so send a page containing a Javascript to redirect to a
    > Javascript-capable version of your page, which clearly would then only
    > be reached if script were actually enabled.
    >
    > An example : http://www.15seconds.com/issue/030303.htm
    >
    > -- PH
    >
     
    Jeremy Chapman, Jun 14, 2006
    #3
  4. Jeremy Chapman wrote:
    > Is there any way via server side code to determine if the browser supports
    > javascript?


    It's often considered more elegant to determine JavaScript capabilities
    on the client and to degrade gracefully if it doesn't.

    For example:

    <a href="nojs.html" onclick="doSomething();return false">Go</a>

    This way, the function is executed if JS is enabled. return false
    prevents the HREF to be displayed. If JS is off, the HREF is executed
    and nojs.html is displayed, which is a page explaining why the user
    experience would be so much better with JS.

    Also, if JS is on, you can use object detection to see if only certain
    functions are enabled:

    if ( document.getElementById )
    {
    document.getElementById( "..." ).value = "...";
    }
    else
    {
    if ( document.all )
    {
    document.all[ "..." ].value = "...";
    }
    else
    {
    alert( "You're doomed" );
    }
    }

    HTH,
    Laurent
    --
    Laurent Bugnion, GalaSoft
    Software engineering: http://www.galasoft-LB.ch
    Private/Malaysia: http://mypage.bluewin.ch/lbugnion
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion, Jun 15, 2006
    #4
    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. Lance

    browser javascript capabilities

    Lance, Aug 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,247
    clintonG
    Aug 14, 2004
  2. Almaya
    Replies:
    0
    Views:
    363
    Almaya
    May 5, 2007
  3. Arne

    Discover Credentials for Proxy Server

    Arne, Nov 19, 2008, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    719
  4. Ken Fine
    Replies:
    1
    Views:
    163
    Invotion
    Jan 26, 2004
  5. pantagruel
    Replies:
    4
    Views:
    112
    pantagruel
    Aug 31, 2005
Loading...

Share This Page