Professional Web Applications Themes

How do I check browser type then compage in cfif - Coldfusion - Advanced Techniques

I have some code that is only supported in Navigator 3.0 and up, and IE4.0. I want to be able to check the browser then have it compare their browser in a list so that it does something like... <cfif BROWSER is Navigator 3.0 or up and BROWSER is IE 4.0 and up> SHOW SUPPORTED CODE <CFELSE> SHOW SIMPLE CODE </cfif> something like that but I dont know how to check browser and compare. New to this concept.... Thanks a bunch!...

  1. #1

    Default How do I check browser type then compage in cfif

    I have some code that is only supported in Navigator 3.0 and up, and IE4.0. I
    want to be able to check the browser then have it compare their browser in a
    list so that it does something like...

    <cfif BROWSER is Navigator 3.0 or up and BROWSER is IE 4.0 and up>

    SHOW SUPPORTED CODE

    <CFELSE>
    SHOW SIMPLE CODE
    </cfif>

    something like that but I dont know how to check browser and compare. New to
    this concept....


    Thanks a bunch!

    davellaman Guest

  2. #2

    Default Re: How do I check browser type then compage in cfif

    Hi davellaman

    The Users' browser type is available in the CGI.HTTP_USER_AGENT variable.
    Turn on debugging in CF Admin to have all CGI variables displayed.

    HTH
    zoeski80 Guest

  3. #3

    Default Re: How do I check browser type then compage in cfif

    Alternatively you can use Javascript to detect browser type and version

    eg.
    navigator.appName
    navigator.appVersion

    http://javascriptkit.com/javatutors/navigator.shtml
    zoeski80 Guest

  4. #4

    Default Re: How do I check browser type then compage in cfif

    Yea thats what I am trying to use but I dont know what to compare the values
    too...

    for example i have

    <cfif CGI.HTTP_USER_AGENT eq "?????">

    in a few tests on different browsers, CGI.HTTP_USER_AGENT variables equal as
    follows=

    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414
    Firefox/1.0.3

    so how would I check if its supported in Navigator 3.0 and up, and IE4.0 and up

    any help would be greatly appreciated.

    thanks

    davellaman Guest

  5. #5

    Default Re: How do I check browser type then compage in cfif

    You just do a findNoCase on the string to see if it finds certain sub-strings

    if using netspace it will have Netscape/<VERSION> within the string somewhere
    eg. Netscape/7.1

    if using IE it will have MSIE <VERSION> eg. MSIE 6.0

    Just do CFIF FindNoCase("netscape", CGI.HTTP_USER_AGENT) to dermine the type
    of browser

    OR could do an RE to get the version returned in the array using something
    this (not tested)
    REFindNoCase("netscape/([[:digit:]])", CGI.HTTP_USER_AGENT, 1, true)

    You just need to work out what you need to search for within the string for
    the different browser and version types and do the appropriate list finds.

    HTH

    zoeski80 Guest

  6. #6

    Default Re: How do I check browser type then compage in cfif

    thanks il give it a try!

    I kept recieving errors on my above post so it was duplicated a bunch of time,

    sorry about that


    Mark
    davellaman Guest

  7. #7

    Default Re: How do I check browser type then compage in cfif

    Best I can do is post the actual values for IE and Firefox

    HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
    HTTP_USER_AGENT=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12)
    Gecko/20050915 Firefox/1.0.7

    Ken

    The Guest

  8. #8

    Default Re: How do I check browser type then compage in cfif

    this is what I use....

    <cffunction name="isBrowserCompatible" output="No" returntype="boolean">
    <cfscript>
    sAgent = lCase( cgi.HTTP_USER_AGENT );
    isCompatibleBrowser = false;

    // check for Internet Explorer ( >= 5.5 )
    if( find( "msie", sAgent ) and not find( "mac", sAgent ) and not find(
    "opera", sAgent ) )
    {
    // try to extract IE version
    stResult = reFind( "msie ([5-9]\.[0-9])", sAgent, 1, true );
    if( arrayLen( stResult.pos ) eq 2 )
    {
    // get IE Version
    sBrowserVersion = mid( sAgent, stResult.pos[2], stResult.len[2] );
    if( sBrowserVersion GTE 5.5 )
    isCompatibleBrowser = true;
    }
    }
    // check for Gecko ( >= 20030210+ )
    else if( find( "gecko", sAgent ) )
    {
    // try to extract Gecko version date
    stResult = reFind( "gecko/(200[3-9][0-1][0-9][0-3][0-9])", sAgent, 1, true );
    if( arrayLen( stResult.pos ) eq 2 )
    {
    // get Gecko build (i18n date)
    sBrowserVersion = mid( sAgent, stResult.pos[2], stResult.len[2] );
    if( sBrowserVersion GTE 20030210 )
    isCompatibleBrowser = true;
    }

    }
    return isCompatibleBrowser;
    </cfscript>
    </cffunction>

    Cheers



    RobGonda Guest

Similar Threads

  1. <cfif form.secret_word EQ #session.secretWord#> thankyou <cfelse>sorry </cfif>
    By Hydrowizard in forum Coldfusion - Getting Started
    Replies: 4
    Last Post: April 28th, 06:21 PM
  2. cfif cfelse help (check me)
    By frank_tudor in forum Macromedia ColdFusion
    Replies: 2
    Last Post: September 21st, 03:19 PM
  3. cfif simple null value check
    By frank_tudor in forum Macromedia ColdFusion
    Replies: 2
    Last Post: September 20th, 09:30 PM
  4. CFIF URL check not working....
    By redman2215 in forum Macromedia ColdFusion
    Replies: 1
    Last Post: June 25th, 12:07 AM
  5. check/get variable type?
    By ed in forum PERL Miscellaneous
    Replies: 1
    Last Post: June 24th, 01:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139