This tutorial will show how to reference the Browser object to retrieve information about what your client can display. VB version.
In this tutorial, we reference the Browser Object to display information about both the Client and the Browser. This could help us determine how our users see our page, depending upon their settings. These could also help us display our page differently so that our users get the most out of the site, no matter what their set-up.
We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!
The text attribute of each label in the ASPX page will be dynamically changed upon runtime, depending upon the user configuration / browser.First, let's create a layout to display the information:
| <form id="form1" runat="server"> <div> Browser Capabilities:<br /> </form> <table style="width: 95%; position: static; text-align: left"> <tr> </table><td style="vertical-align: top; width: 30%; text-align: right"> ActiveX Controls:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label1" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> AOL:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label2" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Background Sounds:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label3" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> CDF:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label4" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> .NET Framework:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label5" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Cookies:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label6" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> ECMA:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label7" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> HTML Frames:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label8" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Java Applets:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label9" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Browser Version:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label10" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> Broswer Platform:</td> <td style="vertical-align: top; width: 70%; text-align: left"> </tr><asp:Label ID="Label11" runat="server"></asp:Label></td> <tr> <td style="vertical-align: top; width: 30%; text-align: right"> </tr></td> <td style="vertical-align: top; width: 70%; text-align: left"> </td> <br /> </div> |
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
The following code checks for values for specific properties of the Browser Object.We are able to output these values to the user to notify them, but we are also able to use these values in the code to display our page differently to different users. For example, not using ActiveX Controls if the user's browser does not support ActiveX.
The code-behind should look something like this:
| Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Partial Public Class _Default Inherits System.Web.UI.Page End Class Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Request.Browser.ActiveXControls = True Then End SubLabel1.Text = "This browser supports ActiveX Controls." Else Label1.Text = "This browser does not support ActiveX controls." End IfIf Request.Browser.AOL = True Then Label2.Text = "This browser is AOL." Else Label2.Text = "This browser is not AOL." End IfIf Request.Browser.BackgroundSounds = True Then Label3.Text = "This browser supports Background Sounds." Else Label3.Text = "This browser does not support Background Sounds." End IfIf Request.Browser.CDF = True Then Label4.Text = "This browser supports Channel Definition Format." Else Label4.Text = "This browser does not support Channel Definition Format." End IfIf Request.Browser.ClrVersion.ToString() <> "0.0" Then Label5.Text = "This client supports the .NET Framework! You are running version " & Request.Browser.ClrVersion.ToString() Else Label5.Text = "You do not have the .NET Framework installed on your machine." End IfIf Request.Browser.Cookies = True Then Label6.Text = "This browser supports Cookies." Else Label6.Text = "This browser does not currently support Cookies." End IfLabel7.Text = "You are running version " & Request.Browser.EcmaScriptVersion.ToString() & " of ECMA Script." If Request.Browser.Frames = True Then Label8.Text = "This browser supports HTML Frames." Else Label8.Text = "This browser does not support HTML Frames." End IfIf Request.Browser.JavaApplets = True Then Label9.Text = "This browser supports Java Applets." Else Label9.Text = "This browser does not support Java Applets." End IfLabel10.Text = Request.Browser.Type.ToString() & "." & Request.Browser.MinorVersion.ToString() Label11.Text = Request.Browser.Platform |
No comments:
Post a Comment