Home>

This article will continue to introduce some web dynamic features written in ASP.Due to the inconsistency of web browser standards, how to make your own website adapt to different browsers has become the most headache for website designers.In today's situation,We are unwilling and impossible to abandon any kind of customer base in netscape or ie,But sometimes we have to consider the actual browsing effect of the client browser.In the past, we used to write a program in javascript to identify the different browsers used by the client.So let's take a look today how to use asp to achieve this more easily and accurately.Put the following code,Cut and paste into your notebook and save it as browser.asp.

<%@language=vbscript%>
<html>
<head>
Title<title>identify client browsers using browser performance components provided by asp</title>
</head>
<body bgcolor="white" topmargin="10" leftmargin="10">
<font size="4" face="arial, helvetica">
<b>Use browser performance components provided by asp to identify<br>Other client browser</b></font><br>
<hr size="1" color="#000000">
!<!-Define and create browser performance objects->
<%
Dim bc
Set bc=server.createobject ("mswc.browsertype")
%>
!<!-Describe customer browser information in the form->
<table border=1>
<tr>
<td>browser name</td>
<td><%= bc.browser%></td>
<tr>
<td>browser version</td>
<td><%= bc.version%></td>
<tr>
<td>major version</td>
<td><%= bc.majorver%></td>
<tr>
<td>minor version</td>
<td><%= bc.minorver%></td>
<tr>
<td>frame support</td>
<td><%= bc.frames%></td>
<tr>
<td>table support</td>
<td><%= bc.tables%></td>
<tr>
<td>cookie support</td>
<td><%= bc.cookies%></td>
<tr>
<td>background sound support</td>
<td><%= bc.backgroundsounds%></td>
<tr>
<td>vbscript support</td>
<td><%= bc.vbscript%></td>
<tr>
<td>javascript support</td>
<td><%= bc.javascript%></td>
</table>
</body>
</html>

Browse Browse the file with http,Depending on the browser used,You will see a page similar to the one below (asp2b.gif). In this example we use an activex component provided by ASP-"browser capabilities". activex components run on a web server as part of a web-based application,Components provide the main functions of the application (such as accessing, modifying databases, etc.) so that web designers do not have to create or re-create code that performs these tasks,Which improves work efficiency,The activex components will be discussed in detail in the future.In order to identify client browsers using asp,Here we use the "browser capabilities" component to create a browser type object that provides a user script with a description of the client's web browser capabilities,When the browser is connected to a web server,It automatically sends a useragenthttp header, which is an ascii string declaring the browser and its version. This browser type object compares the title with the entries in the browsercap.ini file (win98, iis3, and iis4 users can "win98 \ system \ inersrv", "\ winnt \ system32 \ inetsrv \ asp \ in the following directories, respectively cmpnts "," \ winnt \ system32 \ inetsrv "). If a match is found,The browser type object will consider the browser list property to match the useragent title.If the object does not find an entry in the browscap.ini file that matches the title,Then the default browser properties will be used.If the object does not find a match and the default browser settings are not specified in the browscap.ini file,Then it sets each attribute to the string "unknown". We can add properties or new browser definitions to the component by updating the browscap.ini file,As a result, the browser scope and accuracy of asp recognition are expanded.Below is a list ofA part of browscap.ini (not including the comment part):

[ie 4.0] ;;httpuseragentheader

browser=ie ;;Specify the name of the browser.

version=4.0 ;;Specify the version number of this browser.

majorver=4 ;;specify the major version number

minorver=0 ;;specify minor version number

frames=true ;;Specify whether this browser supports frames.

tables=true ;;Specify whether the browser supports tables.

cookies=true ;;Specify whether this browser supports cookies.

backgroundsounds=true ;;Specify whether this browser supports background music.

vbscript=true ;;Specify whether this browser supports vbscript.

javascript=true ;;Specify whether this browser supports jscript.

javaapplets=true ;;Specify whether this browser supports java programs.

activexcontrols=true ;;Specify whether this browser supports activex controls.

win16=false ;;specify whether the browser supports win16

beta=false ;;Specify whether this browser is beta.

cdf=true ;;Specify whether this browser supports the channel definition format for web prediction.

;ie 4.01

[mozilla/4.0 (compatible;msie 4.01 *;windows 95)]

parent=ie 4.0 ;;The parent tag allows the second browser to inherit the definition of the first browser

version=4.01

minorver=01

platform=win98

;;default browser ;;Specify the default browser settings

[default browser capability settings]

browser=default

frames=false

tables=true

cookies=false

backgroundsounds=false

vbscript=false

javascript=false

In the example above,The parent tag allows the second browser to inherit the definition of the first browser,So that the Microsoft Internet Explorer 4.01 definition inherits all the attributes of the Microsoft Internet Explorer 4.0 definition (for example, frames=true, tables=true, and cookies=true). And specify the platform by adding the platform=win98 line,Rewrite version information with version=4.01.

In previous browser.asp we just listed the properties of the client browser one by one,Let's add some dynamic effects.Copy and paste the following code into the file browser.asp (Editor note:For display convenience,Add a space after all "&";Please be careful to remove it in actual use. ):

<%if (bc.frames=true) then%>
Your browser supports frames!<br>
<%else%>
Don't you still use a browser that doesn't support frames
<%end if%>
<%if (bc.tables=true) then%>
Your browser supports forms.
<br>
<%else%>
Are you still using a browser that does not support forms???<br>
<%end if%>
<%if (bc.backgroundsounds=true) then%>
Have you heard wonderful music???<br>
<%else%>
Unfortunately, your browser does not support background music.<br>
<%end if%>
<%if (bc.vbscript=true) then%>
Your browser supports vbscript.<br>
<%else%>
Your browser does not support vbscrip.<br>
<%end if%>
<%if (bc.javascript=true) then%>
Your browser supports javascript.<br>
<%else%>
Your browser does not support javascript.<br>
<%end if%>

Refresh Refresh browser.asp in your browser, the program will automatically recognize the properties of the browser and dynamically display different information.It is not difficult to find that almost no complicated programming is used in the entire browser.asp file,It is easy to achieve the effect of dynamically identifying the client browser and dynamically generating a response event.In fact, the key to this program lies in the aforementioned activex component-"browser capabilities". Its function is similar to a function. Simply calling the component in the program can achieve the effect i want.

asp
  • Previous Introduction to ASP Basics Part 1 (ASP Technology Introduction)
  • Next Tips for using multi-port access under WampServer