BrowserHawk makes it easy to detect mobile devices. Based on this information you can easily have your own code redirect mobile device users to a different version of your site or dynamically serve alternate content to such devices on-the-fly.
To detect a mobile device, simply check to see if the MobileDevice property is True. Furthermore you can use the DeviceName property if you wish to know which device it is.
Note: The iPad is not categorized by BrowserHawk as a mobile device by design. Therefore the MobileDevice property will return False for the iPad. This decision was made based on feedback from customers who requested this behavior because they wish to treat the iPad like a traditional browser due to its larger screen size.
The following examples demonstrate ways in which you may want to use the MobileDevice and or DeviceName properties:
Example 1: Redirect all mobile users, except iPad users, to a mobile version of your site
C# code snippet:
<%
BrowserObj browObj = BrowserObj.GetBrowser();
if (browObj.MobileDevice == true) {
Response.Redirect("http://mobile.mysite.com/");
}
%>
ASP code snippet:
<%
set bhObj = Server.CreateObject("cyScape.browserObj")
if browObj.MobileDevice = true then
Response.Redirect "http://mobile.mysite.com/"
end if
%>
Example 2: Redirect all mobile users, including iPad users, to a mobile version of your site
C# code snippet:
<%
BrowserObj browObj = BrowserObj.GetBrowser();
if (browObj.MobileDevice == true || browObj.DeviceName == "iPad") {
Response.Redirect("http://mobile.mysite.com/");
}
%>
ASP code snippet:
<%
set bhObj = Server.CreateObject("cyScape.browserObj")
if browObj.MobileDevice = true OR browObj.DeviceName = "iPad" then
Response.Redirect "http://mobile.mysite.com/"
end if
%>
Example 3: Redirect different mobile devices to different mobile versions of your site
C# code snippet:
<%
BrowserObj browObj = BrowserObj.GetBrowser();
if (browObj.DeviceName == "iPhone") {
Response.Redirect("http://iphone.mysite.com/");
else if (browObj.DeviceName == "iPod Touch") {
Response.Redirect("http://itouch.mysite.com/");
else if (browObj.DeviceName == "iPad") {
Response.Redirect("http://ipad.mysite.com/");
else if (browObj.DeviceName == "Droid") {
Response.Redirect("http://droid.mysite.com/");
else if (browObj.DeviceName == "Blackberry") {
Response.Redirect("http://blackberry.mysite.com/");
else if (browObj.DeviceName == "Pre") {
Response.Redirect("http://palmpre.mysite.com/");
else if (browObj.DeviceName == "Pixi") {
Response.Redirect("http://pixi.mysite.com/");
else if (browObj.DeviceName == "Nexus One") {
Response.Redirect("http://nexusone.mysite.com/");
else if (browObj.MobileDevice == true) {
Response.Redirect("http://othermobile.mysite.com/");
}
%>
ASP code snippet:
<%
set bhObj = Server.CreateObject("cyScape.browserObj")
if browObj.DeviceName = "iPhone" then
Response.Redirect "http://iphone.mysite.com/"
elseif browObj.DeviceName = "iPod Touch" then
Response.Redirect "http://itouch.mysite.com/"
elseif browObj.DeviceName = "iPad" then
Response.Redirect "http://ipad.mysite.com/"
elseif browObj.DeviceName = "Droid" then
Response.Redirect "http://droid.mysite.com/"
elseif browObj.DeviceName = "Blackberry" then
Response.Redirect "http://blackberry.mysite.com/"
elseif browObj.DeviceName = "pre" then
Response.Redirect "http://palmpre.mysite.com/"
elseif browObj.DeviceName = "Pixi" then
Response.Redirect "http://pixi.mysite.com/"
elseif browObj.DeviceName = "Nexus One" then
Response.Redirect "http://nexusone.mysite.com/"
elseif browObj.MobileDevice = true then
Response.Redirect "http://othermobile.mysite.com/"
end if
%>
Example 4: Redirect all tablet users to a different version of your site
C# code snippet:
<%
BrowserObj browObj = BrowserObj.GetBrowser();
if (browObj.DeviceType =="Tablet") {
Response.Redirect("http://tablet.mysite.com/");
}
%>
ASP code snippet:
<%
set bhObj = Server.CreateObject("cyScape.browserObj")
if browObj.DeviceType = "Tablet" then
Response.Redirect "http://tablet.mysite.com/"
end if
%>
See Also:
MobileDevice Property (ActiveX / .NET)
DeviceName Property (ActiveX / .NET)
DeviceType Property (ActiveX / .NET)