Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
Go Back  Xtreme Visual Basic Talk > > > Finding Browser Type in Classic ASP


Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2013, 05:12 AM
bobcory's Avatar
bobcory bobcory is offline
Contributor
 
Join Date: Jun 2003
Location: NW UK
Posts: 454
Default Finding Browser Type in Classic ASP


I am testing for various browser types in classic asp. Here is my routine. I can check this works OK for Chrome, Firefox and MIE because I have them installed on my PC.

Code:
Function BrowserName      'as String
  dim strContent 'as String

  strContent = Request.ServerVariables("HTTP_USER_AGENT")
  strContent = lcase(strContent)

  'Test for: Chrome
  if instr(strContent, "chrome") > 0 then
    BrowserName = "Chrome"
    exit function
  end if

  'Test for: "Firefox"
  if instr(strContent, "firefox") > 0 then
    BrowserName = "Firefox"
    exit function
  end if

  'Test for: Explorer
  if instr(strContent, "msie") > 0 then
    BrowserName = "MSI Explorer"
    exit function
  end if

  'If still here ... other
  BrowserName = "Another Browser"

end function
I now need to extend this to Opera and Safari but don't want to actually install them on my machine. Does anybody know what the crucial words to look for are? I assume opera and safari but maybe not...??
.
Reply With Quote
  #2  
Old 08-09-2013, 05:28 AM
PlausiblyDamp's Avatar
PlausiblyDampFinding Browser Type in Classic ASP PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

http://www.useragentstring.com/pages...gentstring.php has just about every user agent string you can think off listed.

Just as an aside is there a reason you are needing to detect the browser type?
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 08-09-2013, 05:46 AM
bobcory's Avatar
bobcory bobcory is offline
Contributor
 
Join Date: Jun 2003
Location: NW UK
Posts: 454
Default

Quote:
Originally Posted by PlausiblyDamp View Post
http://www.useragentstring.com/pages...gentstring.php has just about every user agent string you can think off listed.

Just as an aside is there a reason you are needing to detect the browser type?
Thanks for that!

Two main reasons, my website works much better on Chrome and Firefox (MIE opens a new Window when really a Tab suits much better)

Secondly, the Right click to save is different for each type and I thought I would customise it so

If Firefox "Save Link As ..."
If Opera "Save Linked Content As"

etc etc

[Edit] This is tricky because:

Chrome refers to Safari in the string
MSIE refers to Chrome in the string
Opera refers to Firefox and MSIE in the string

So, here is my final code in case it helps somebody

Code:
Function BrowserName      'as String
  dim strContent 'as String

  strContent = Request.ServerVariables("HTTP_USER_AGENT")
  strContent = lcase(strContent)

  'FIRST: Test for Opera
  'Note: Opera is the ONLY popular browser that refers to "Opera"
  if instr(strContent, "opera") > 0 then
    BrowserName = "Opera"
    exit function
  end if

  'SECOND: Test for Explorer
  'Note: Opera MAY contain a reference to MSIE but Opera has ALREADY been found
  if instr(strContent, "msie") > 0 then
    BrowserName = "MSI Explorer"
    exit function
  end if

  'THIRD: Test for "Firefox"
  'Note: Opera MAY contain a reference to "Firefox" but Opera has ALREADY been found
  if instr(strContent, "firefox") > 0 then
    BrowserName = "Firefox"
    exit function
  end if

  'FOURTH: Test for "Chrome"
  'Note: MSIE MAY contain a reference to "Chrome" but MSIE has ALREADY been found
  if instr(strContent, "chrome") > 0 then
    BrowserName = "Chrome"
    exit function
  end if

  'FIFTH: Test for "Safari"
  'Note: Chrome MAY contain a reference to "Safari" but Chrome has ALREADY been found
  if instr(strContent, "safari") > 0 then
    BrowserName = "Safari"
    exit function
  end if


  'If still here ... other
  BrowserName = "Another Browser"

end function
.




.

Last edited by bobcory; 08-10-2013 at 04:30 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
 
Finding Browser Type in Classic ASP
Finding Browser Type in Classic ASP
 
-->