<% ' ASP Functions to manipulate media types ' see original post for description: ' http://mezzoblue.com/archives/2008/03/18/mediatyping Function setDisplaySelectorUrl(displayType) currentUrl = "" if Request.ServerVariables("QUERY_STRING") <> "" then currentUrl = "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") & "?" & Request.ServerVariables("QUERY_STRING") else currentUrl = "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") end if setDisplaySelectorUrl = currentUrl hasGetValue = InStr(currentUrl,"?") if hasGetValue = 0 then setDisplaySelectorUrl = "?media=" & displayType else hasGetValue = InStr(currentUrl,"media=") if hasGetValue = 0 then setDisplaySelectorUrl = "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") & "?" & Request.ServerVariables("QUERY_STRING") & "&media=" & displayType else str = "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") & "?" & Request.ServerVariables("QUERY_STRING") str = Replace(str, "media=screen", "media=" & displayType) str = Replace(str, "media=zoom", "media=" & displayType) str = Replace(str, "media=mobile", "media=" & displayType) setDisplaySelectorUrl = str end if End If End Function ' this function takes two arguments: an array of user agents, and a specific user agent ' it will then try to see if the specific user agent exists within the array ' if so, it will return true, otherwise it returns false. Function checkMediaType(uaList, uaKnown) ' check user agent string against array, return true if found, or false if not found ' checking method changed by Karen, since it did not work :) checkMediaType = false For Each ua in uaList if (not Trim(ua) = "") then pos = Instr(LCASE("$" & uaKnown), LCASE(ua)) If pos <> 0 Then checkMediaType = true End If End If Next End Function ' this function takes one argument: a string value that specifies a media profile ' it will then set a cookie in the browser ' it returns the media profile value, to be used as a variable later in the page Function selectMedia(media) Response.Cookies("media")=media Response.Cookies("login").Expires=DateAdd("S", "31536000", Date) selectMedia = media End Function ' ============================== ' media check Dim userAgentsMobile(20) userAgentsMobile(0) = "Blazer" userAgentsMobile(1) = "Palm" userAgentsMobile(2) = "Handspring" userAgentsMobile(3) = "Nokia" userAgentsMobile(4) = "Kyocera" userAgentsMobile(5) = "Samsung" userAgentsMobile(6) = "Motorola" userAgentsMobile(7) = "Smartphone" userAgentsMobile(8) = "Windows CE" userAgentsMobile(9) = "Blackberry" userAgentsMobile(10) = "WAP" userAgentsMobile(11) = "Smartphone" userAgentsMobile(12) = "SonyEricsson" userAgentsMobile(13) = "PlayStation Portable" userAgentsMobile(14) = "LG" userAgentsMobile(15) = "MMP" userAgentsMobile(16) = "OPWV" userAgentsMobile(17) = "Symbian" userAgentsMobile(18) = "EPOC" userAgentsMobile(19) = "iPhone" userAgentsMobile(20) = "iPod" ' array of tv devices Dim userAgentsTv(3) userAgentsTv(0) = "Nintendo Wii" userAgentsTv(1) = "Playstation 3" userAgentsTv(2) = "WebTV" ' show standard version by default Dim mediaVersion mediaVersion = "screen" ' toggle media version if cookie is set If (Not IsNull(Request.Cookies("media")) and Not(Trim(Request.Cookies("media")) = "")) then if (Request.Cookies("media") = "zoom") then mediaVersion = selectMedia("zoom") elseif (Request.Cookies("media") = "mobile") then mediaVersion = selectMedia("mobile") elseif (Request.Cookies("media") = "screen") then mediaVersion = selectMedia("screen") end if Else ' if no cookie found, sniff media type then set cookie knownUserAgent = false ' compare the device arrays against the user agent mediaTypeMobile = checkMediaType(userAgentsMobile, Request.ServerVariables("HTTP_USER_AGENT")) ' if media version is found, set a media type cookie, otherwise flag this browser as screen to save time on future loads if mediaTypeMobile = true then mediaVersion = selectMedia("mobile") else mediaVersion = selectMedia("screen") end if End If ' override media version and set a new cookie if they have selected a "show {media} site" link If Not isnull(Request.QueryString("media")) AND trim(Request.QueryString("media")) <> "" then if (Request.QueryString("media") = "mobile") then mediaVersion = selectMedia("mobile") elseif (Request.QueryString("media") = "zoom") then mediaVersion = selectMedia("zoom") else mediaVersion = selectMedia("screen") end if End If %> View Royal - OCP Review 2011: Background Materials <% if (mediaVersion = "zoom") then Response.Write("") Response.Write("") elseif (mediaVersion = "mobile") then Response.Write("") Response.Write("") Response.Write("") Response.Write("") else %> <% end if %>

View Royal

Liveable, green, sustainable.

Display: <% Response.Write(" Standard ") %> | <% Response.Write(" Mobile ") %> | <% Response.Write(" High Contrast ") %>