Detecting Browser Capabilities With BrowserHawk - BrowserHawk example
(Page 5 of 6 )
Now that we've taken a look at the BrowserHawk application and some of its methods and members, let's create an example that uses BrowserHawk to its fullest extent.
Let's pretend for a minute that we're creating an extremely bandwidth-intensive site that requires its users to have a minimum connection speed of 20KB/second, Flash support, a minimum screen resolution of 1024x768, JavaScript enabled, and at least version 3 of Microsoft’s MSXML parser.
Here's the ASP code that we could use to check that the visitors web browser conforms to the requirements outlined above:
<%
On Error Resume Next
dim objBH
dim strSpeed
dim lngSpeed
dim intCDepth
dim blnFlash
dim intWidth
dim intHeight
dim blnJS
dim blnMSXML
dim strErr
set objBH = Server.CreateObject("cyScape.browserObj")
// Get the browsers extended properties
objBH.SetExtProperties "ConnectionSpeed, Height, Width, JavaScriptEnabled, MSXML"
objBH.GetExtPropertiesEx
// Save the results as variables
strSpeed = objBH.Translate("ConnectionSpeed")
blnFlash = CBool(objBH.Plugin_Flash)
intWidth = CInt(objBH.Width)
intHeight = CInt(objBH.Height)
blnJS = CBool(objBH.JavaScriptEnabled)
blnMSXML = CBool(objBH.MSXML)
// Extract the numerical speed as KB's
lngSpeed = CLng(Mid(strSpeed, Instr(1, strSpeed, "(") + 1, Instr(1, strSpeed, " ")-1))
if lngSpeed > 20 and blnFlash and intWidth >= 1024 _
and intHeight >= 768 and blnJS and blnMSXML then
'Users browser conforms to our requirements
Response.Write "Your browser passed our test"
else
strErr = "<ul>"
if lngSpeed < 20 then
strErr = strErr & "<li>Your connection speed is too sow</li>"
end if
if not blnFlash then
strErr = strErr & "<li>You need flash</li>"
end if
if intWidth < 1024 or intHeight < 768 then
strErr = strErr & "<li>You need at least a 1024 x 768 resolution</li>"
end if
if not blnJS then
strErr = strErr & "<li>You need JavaScript enabled</li>"
end if
if not blnMSXML then
strErr = strErr & "<li>You need MSXML enabled</li>"
end if
strErr = strErr & "</ul>"
Response.Write "Your browser failed our test:<br>"
Response.Write strErr
end if
%>I'm using Internet Explorer 5.5 with all of the features we require enabled, so the output from my browser looks like this:

By turning of JavaScript from the tools menu, several of BrowserHawk's features are disabled. Here's the output in my browser when JavaScript is disabled:

Next: Conclusion >>
More ASP Articles
More By Annette Tennison