This article is the second entry in the basic ASP. The first article shows some of the most basic methods of ASP dynamic website design. I believe that through practice, you have already gained the most basic understanding of ASP. This article will further introduce some of the ASP dynamic websites. Basic tips, friends who need it can refer to
This article will continue to introduce some dynamic features of WEB written in ASP. Due to the inconsistency of WEB browser standards, how to adapt the website you make to various browsers has become the most troublesome thing for website designers. Under the current situation, we are unwilling and cannot abandon it. Netscape or IE any customer group, but sometimes we have to consider the actual browsing effect of client browsers. In the past, we often used JavaScript to write a program to distinguish the different browsers used by clients. So today Let's see how to achieve this with more convenient and precise use of ASP. Cut the following code into your Notebook and save it as browser.asp.
- <%@LANGUAGE=VBScript%>
- <HTML>
- <HEAD>
- <TITLE>Use the browser performance components provided by ASP to identify customer browsers</TITLE>
- </HEAD>
- <BODYBGCOLOR=Whitetopmargin=10leftmargin=10>
- <fontsize=4face=Arial,Helvetica>
- <b>Use the browser performance components provided by ASP to identify the client browser</b></font><br>
- <hrsize=1color=#000000>
- <!--Define and create browser performance objects-->
- <%
- Dimbc
- Setbc=Server.CreateObject(MSWC.BrowserType)
- %>
- <!--Describe the information about the client browser in the form-->
- <Tableborder=1>
- <tr>
- <td>BrowserName</td>
- <td><%=bc.Browser%></Td>
- <tr>
- <td>BrowserVersion</td>
- <td><%=bc.Version%></Td>
- <tr>
- <td>MajorVersion</td>
- <td><%=bc.Majorver%></Td>
- <tr>
- <td>MinorVersion</td>
- <td><%=bc.Minorver%></Td>
- <tr>
- <td>FrameSupport</td>
- <td><%=bc.Frames%></Td>
- <tr>
- <td>TableSupport</td>
- <td><%=bc.Tables%></Td>
- <tr>
- <td>CookieSupport</td>
- <td><%=bc.Cookies%></Td>
- <tr>
- <td>BackgroundSoundSupport</td>
- <td><%=bc.BackgroundSounds%></Td>
- <tr>
- <td>VBScriptSupport</td>
- <td><%=bc.VBScript%></Td>
- <tr>
- <td>JavaScriptSupport</td>
- <td><%=bc.JavaScript%></Td>
- </table>
- </BODY>
- </HTML>
Some content in browser.ini (excluding comments):
Use http to browse the file. Depending on the browser you are using, you will see a page similar to the image below (Asp2b.gif). In this example, we used an ActiveX component provided by ASP--Browser Capabilities. ActiveX components run on a web server as part of a web-based application. The components provide the main functions of the application (such as accessing, modifying databases, etc.), so that WEB designers do not have to create or recreate code that performs these tasks, so that Improved work efficiency and will be discussed in detail in the future. To identify client browsers using ASP, here we use the Browser Capabilities component to create a Browser Type object that provides user scripts with client web browser functionality descriptions, which will be used when the browser connects to a web server. Automatically send a UserAgentHTTP header, which is an ASCII string declaring the browser and its version. This Browser Type object compares the title with the items in the Browscap.ini file (Win98, IIS3, and IIS4 users can win98/system/inersrv, /winnt/system32/inetsrv/asp/cmpnts, / winnt/system32/inetsrv Found the file). If a matching item is found, the Browser Type object will consider that the browser list attribute matches the UserAgent title. If the object cannot find an item matching the title in the browser.ini file, the default browser properties will be used. If the object has neither a match found and the default browser settings are specified in the browser.ini file, it sets each property to the string UNKNOWN. We can add properties or new browser definitions to this component by updating the browser.ini file, thereby expanding the browser scope and accuracy recognized by ASP. Listed below
[IE 4.0] ;;HTTPUserAgentHeader
browser=IE ;;Specify the name of the browser.
Version=4.0 ;;Specify the version number of this browser.
major=4 ;;Specify the main version number
minorver=0 ;;Specify the secondary version number
frames=TRUE ;;Specify whether the browser supports frames.
tables=TRUE ;;Specify whether the browser supports tables.
cookies=TRUE ;;Specify whether the browser supports cookies.
backgroundsounds=TRUE ;;Specify 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;; Specify whether the browser supports Win16
beta=False ;;Specifies whether the browser is beta version.
cdf=True ;;Specifies whether the browser supports 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 above example, the parent tag allows the second browser to inherit the definition of the first browser so that the Microsoft Internet Explorer4.01 definition can inherit the Microsoft Internet Explorer4.0 definition of all properties (for example, frames=TRUE, tables= TRUE and cookies=TRUE) . And specify the platform by adding the platform=Win98 line, and rewrite the version information with version=4.01.
In the previous browser.asp we just listed the properties of the client browser one by one. Let's add some dynamic effects below. Clip the following code into the file browser.asp (Editor's note: For the convenience of display, all < symbols have been added with extra spaces. Please be careful to remove them when using them in actual use):
- <%if(bc.frames=TRUE)then%>
- Your browser supports framework!<br>
- <%else%>
- Are you still using a browser that does not support frameworks???<br>
- <%endif%>
- <%if(bc.tables=TRUE)then%>
- Your browser supports forms. <br>
- <%else%>
- Are you still using a browser that does not support forms???<br>
- <%endif%>
- <%if(bc.BackgroundSounds=TRUE)then%>
- Have you heard wonderful music???<br>
- <%else%>
- Unfortunately, your browser does not support background music. <br>
- <%endif%>
- <%if(bc.vbscript=TRUE)then%>
- Your browser supports Vbscript. <br>
- <%else%>
- Your browser does not support Vbscript. <br>
- <%endif%>
- <%if(bc.javascript=TRUE)then%>
- Your browser supports Javascript. <br>
- <%else%>
- Your browser does not support Javascript. <br>
- <%endif%>
Refresh browser.asp in your browser, and the program will automatically identify the browser's properties and dynamically display different information. It is not difficult to find that almost no complex programming is used in the entire browser.asp file, and it is easy to dynamically identify the client browser and dynamically generate response events. In fact, the key to this program lies in the Browser Capabilities mentioned above, which is similar to a Function, and you can achieve the effect you want by simply calling the component in the program.
Through these two introductions to ASP, you have already seen that writing ASP programs is quite easy. To master ASP, it is nothing more than mastering the five built-in objects of ASP, as well as the objects, methods and properties of ActiveX components provided by ASP. Of course, it is solid. The scripting language writing ability is also necessary. In future articles, the editor will spend five to six chapters to introduce the functions and usage methods of these built-in objects and components, so please pay attention.