Solved

Browser version detection.

Posted on 2006-07-05
14
302 Views
Last Modified: 2008-02-01
Browser version detection.


Hi all,

I have a site which has sections for only the newer browsers. I am looking for some scripts or examples which could allow me to do the following.

If MyBropwser = IE 5.5 or later Then
Browser = Good
End If

If MyBropwser = FireFox 1.5 or later Then
Browser = Good
End If

If MyBropwser = Netscape 8 or later Then
Browser = Good
End If


If Browser = Good Then
Response.redirect(“GoHere.asp”)
Else
Response.redirect(“GoGetNewBrowser.asp”)
End If

Kind regards
Aplimedia

PS. No too interested in a Javascrip solution.
0
Comment
Question by:aplimedia
  • 5
  • 3
  • 2
  • +4
14 Comments
 
LVL 6

Assisted Solution

by:inviser
inviser earned 100 total points
ID: 17044838
This code will give you the tools you need:

<BODY>

<%
REM set the browser object for me
Set objBrowse = Server.CreateObject("MSWC.BrowserType")
%>
<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>
      <TR>
            <TH>Browser Capability</TH>
            <TH>Value</TH>
      </TR>
      <TR>
            <TD>Browser</TD>
            <TD><%= objBrowse.browser%></TD>
      </TR>
      <TR>
            <TD>Version</TD>
            <TD><%= objBrowse.version%></TD>
      </TR>
      <TR>
            <TD>Beta</TD>
            <TD><%= objBrowse.beta%></TD>
      </TR>
      <TR>
            <TD>Platform</TD>
            <TD><%= objBrowse.platform%></TD>
      </TR>
      <TR>
            <TD>Tables</TD>
            <TD><%= objBrowse.tables%></TD>
      </TR>
      <TR>
            <TD>Frames</TD>
            <TD><%= objBrowse.frames%></TD>
      </TR>
      <TR>
            <TD>Cookies</TD>
            <TD><%= objBrowse.cookies%></TD>
      </TR>
      <TR>
            <TD>Java</TD>
            <TD><%= objBrowse.javaapplets%></TD>
      </TR>
      <TR>
            <TD>ActiveXControls</TD>
            <TD><%= objBrowse.activexcontrols%></TD>
      </TR>
      <TR>
            <TD>Backgroundsounds</TD>
            <TD><%= objBrowse.backgroundsounds%></TD>
      </TR>
      <TR>
            <TD>Javascript</TD>
            <TD><%= objBrowse.javascript%></TD>
      </TR>
      <TR>
            <TD>VBScript</TD>
            <TD><%= objBrowse.vbscript%></TD>
      </TR>
</TABLE>
</BODY>
0
 
LVL 10

Author Comment

by:aplimedia
ID: 17044944
Hi inviser

I have tried your script, which detects IE correctly, however, getsno results at all for firefox, netscape, and thinks Opera8 is netscape 4...

Thanks anyway.

Kind regards

Aplimedia
0
 
LVL 23

Expert Comment

by:adilkhan
ID: 17044951
httpUserAgent=Request.ServerVariables("HTTP_USER_AGENT")

if inStr(httpUserAgent, "MSIE 5") <> 0 then browser="MS IE 5"
if inStr(httpUserAgent, "MSIE 5.1") <> 0 then browser="MS IE 5.1"
if inStr(httpUserAgent, "MSIE 5.5") <> 0 then browser="MS IE 5.5"
if inStr(httpUserAgent, "MSIE 6") <> 0 then browser="MS IE 6"
if inStr(httpUserAgent, "/4.7") <> 0 then browser="NS 4.7x"
if inStr(httpUserAgent, "Netscape6") <> 0 then browser="NS 6"
if inStr(httpUserAgent, "Netscape/7") <> 0 then browser="NS 7"  
if inStr(httpUserAgent, "Opera 5") <> 0 then browser="OPERA 5"  
if inStr(httpUserAgent, "Opera 6") <> 0 then browser="OPERA 6"

Response.write browser
0
 
LVL 10

Author Comment

by:aplimedia
ID: 17044999
I have seen this script elswhere and althought it has a lot to offer, it has limitations. For example in a years time we will have IE 8.2 and Firefox2.5.09. These new version will not pass as their critieria are not listed in the browser checking script.

Thanks for your input.

Kind regards

Aplimedia
0
 
LVL 14

Assisted Solution

by:dfu23
dfu23 earned 100 total points
ID: 17045080
I must recommend against browser detection:
http://www.quirksmode.org/js/support.html

Quick excerpt from the article:

"If you want to know whether the browser that views your page supports certain objects you want to use in your code, you should never EVER use a browser detect. Sure, you know that this–and–that browser will support your code while such–and–so browser won’t. But how about other browsers, obscure browsers?

While browser detection works well enough for 90% of your visitors, some obscure browsers won't be treated correctly and browsers that appear after you've written the page may not be adequately covered either. The results would be either a stream of error messages or a script that isn't called while the browser can easily handle it. In both cases, you're cheating your end users and coding incorrectly."
0
 
LVL 23

Expert Comment

by:adilkhan
ID: 17045137
dfu23, Article is great, but that Solution is good for client side javaScript only.
Question is been asked in ASP TA, so we dont know whats the purpose of this Script.
0
 
LVL 10

Author Comment

by:aplimedia
ID: 17045152
>>But how about other browsers, obscure browsers?

I will only accept:

IE 5.5 or higher
FireFoxor
Netscape 8 or higher
Oper 8 or higher.


Everything else gets chucked out...

Aplimedia
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Author Comment

by:aplimedia
ID: 17045165
And specifically said:

PS. No too interested in a Javascrip solution.


Aplimedia
0
 
LVL 23

Accepted Solution

by:
adilkhan earned 200 total points
ID: 17045241
I am afraid then best Solution is javaScript based only.
seems like your page requires only new Document Objects.

IE 5.5+, firefox and NS 8 all support javaScripts getElementById Method, so you can easily detect.
<Script>
if(document.getElementById) {
  // I  have a Good Browser
 document.location = "i am ok.asp"
 } else {
     alert("Please upgrade your Browser")
 }
</Script>
(Within the HEAD Tags)
0
 
LVL 14

Expert Comment

by:dfu23
ID: 17046047
Then the question is why are you only allowing these "newer" browsers? What functionality needs to be supported by the visitors to your site?

The User Agent String can easily be spoofed ...
0
 
LVL 28

Expert Comment

by:sybe
ID: 17048356
> The User Agent String can easily be spoofed ...

Exactly. There are enough people browsing pretending to the google-spider, so they don't have to registrer in order to read articles.

Browser-detection is crap, you should make your code W3C-compliant, and then check the site with the most common browsers and eventually do some adaptations to correct for the errors in those browsers.

Also don't automatically exclude browsers. Just make a remark that the specific code has been checked for the browsers (and versions) you have checked it with, and that you can not guarantee that it works in other browsers.  But let people free to look at the pages with any browser. It might word you know, even if you did not check.
0
 
LVL 8

Assisted Solution

by:kaliyugkaarjun
kaliyugkaarjun earned 100 total points
ID: 17049983
0
 
LVL 20

Expert Comment

by:Gawai
ID: 17052072
0
 
LVL 10

Author Comment

by:aplimedia
ID: 17061717
Thanks to all.

aplimedia
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now