Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

Browser version detection.

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
aplimedia
Asked:
aplimedia
  • 5
  • 3
  • 2
  • +4
4 Solutions
 
inviserCommented:
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
 
aplimediaAuthor Commented:
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
 
Saqib KhanSenior DeveloperCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
aplimediaAuthor Commented:
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
 
dfu23Commented:
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
 
Saqib KhanSenior DeveloperCommented:
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
 
aplimediaAuthor Commented:
>>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
 
aplimediaAuthor Commented:
And specifically said:

PS. No too interested in a Javascrip solution.


Aplimedia
0
 
Saqib KhanSenior DeveloperCommented:
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
 
dfu23Commented:
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
 
sybeCommented:
> 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
 
kaliyugkaarjunCommented:
0
 
aplimediaAuthor Commented:
Thanks to all.

aplimedia
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now