Introduction to ASP Basics second (ASP Basics) _ Application Tips

Source: Internet
Author: User

This article will continue to introduce some of the Web dynamic features written in ASP. Because of the inconsistent web browser standards so that how to make their own web site to adapt to a variety of different browsers to become the most headaches of web designers, in today's situation, we will not be able to abandon Netscape or any of the customer base IE, But sometimes we have to consider the actual browsing effect of the client browser, in the past we used to write a program of JavaScript to identify the different browsers used by clients, so today let's look at how to use the ASP more convenient and accurate to achieve this goal.   Clip the following code into your notebook and save it as browser.asp.

<%@ LANGUAGE = VBScript%> < html> < head> < title> using ASP-provided browser performance components to identify customer browser </TITLE&GT
   ;  

Browse the file with HTTP, depending on the browser you are using, you will see a page similar to the one in the following image (Asp2b.gif). In this example we used an ASP-supplied ActiveX component-"Browser capabilities". ActiveX components run on a Web server as part of a web-based application, and components provide the primary functionality of the application (such as access, modify databases, and so on) so that Web designers do not have to create or re-create the code to perform these tasks, thereby increasing the efficiency of the work, with the ActiveX Components will be discussed in detail in the future. In order to identify the client browser using ASP, we have created a Browser Type object using the "Browser capabilities" component, which provides user scripts with descriptions of the client Web browser features, and when the browser is connected to a network server, It automatically sends a useragenthttp title, which is an ASCII string that declares the browser and its version. This Browser Type object compares the title to the items in the Browscap.ini file (Win98, IIS3, IIS4 users can "Win98\system\inersrv", "\winnt\system3" in the following directory, respectively) 2\inetsrv\asp\cmpnts "," \winnt\system32\inetsrv "to find the file). If a matching entry is found, the Browser Type object will consider the browser list property to match the useragent header. If the object does not find an entry in the Browscap.ini file that matches the title, the default browser properties are used. If the object does not find a match and the default browser setting is not specified in the Browscap.ini file, it sets each property to the string "UNKNOWN". By updating the Browscap.ini file, we can add attributes or new browser definitions to the component to enlarge the browser scope and accuracy that the ASP recognizes. The following is a list of the contents of the Browscap.ini (excluding the comments section):

[IE 4.0];; HTTPUserAgentHeader
Browser=ie;; Specifies the name of the browser.
version=4.0;; Specifies the version number of the browser.
majorver=4;; Specify the major version number
minorver=0;; Specify a secondary version number
Frames=true;; Specifies whether the browser supports frames.
Tables=true;; Specifies whether the browser supports tables.
Cookies=true;; Specifies whether the browser supports cookies.
Backgroundsounds=true;; Specifies whether the browser supports background music.
Vbscript=true;; Specifies whether the browser supports VBScript.
Javascript=true;; Specifies whether the browser supports JScript.
Javaapplets=true;; Specifies whether the browser supports Java programs.
Activexcontrols=true;; Specifies whether the browser supports ActiveX controls.
Win16=false;; Specifies whether the browser supports Win16
Beta=false;; Specifies whether the browser is a beta version.
Cdf=true;; Specifies whether the 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;; Parent tag allows a second browser to inherit the definition of the first browser
version=4.01
Minorver=01
Platform=win98


;;D Efault Browser;; Specify settings for the default browser
[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 a second browser to inherit the definition of the first browser so that the Microsoft Internet Explorer4.01 definition inherits all of the properties of the Microsoft Internet Explorer4.0 definition (for example, FRA Mes=true, Tables=true and Cookies=true). and by adding platform=win98 rows to specify the platform, rewrite the version information with version=4.01.

In the previous browser.asp we simply listed the client browser's attribute one by one, let's add some dynamic effects here. Clip the following code into the file browser.asp (Edit note: For display convenience, all the "<" symbol after adding a space, the actual use, please pay attention to remove. ):

<% if (Bc.frames = TRUE) then%>
your browser support Framework!< br>
<% else%> are
you still using browsers that do not support frames??? < br>
<% End If%>
<% if (Bc.tables = TRUE) then%>
your browser support form. < br>
<% Else%>
Now you are using browsers that do not support tables??? < br>
<% End If%>
<% if (BC. backgroundsounds = TRUE) Then%>
have heard the 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 browser.asp in your browser, the program will automatically identify the browser's properties and dynamically display different information. It is not difficult to find that in the entire browser.asp file almost no complex programming, it is easy to dynamically identify the client browser and dynamic response to the effect of the event. In fact, the key to this program is the ActiveX component mentioned earlier-"Browser capabilities", which acts like a function, simply by invoking the component in the program to achieve the desired effect.

Through the introduction of these two ASP, we have seen the preparation of ASP program is quite easy, to master the ASP, nothing more than the master ASP built-in five objects, as well as ASP provided by the ActiveX components of objects, methods and attributes, of course, a solid script language writing ability is also necessary. In the future, the small and medium series will use five to six pages to highlight the role of these built-in objects and components and use methods, please pay attention.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.