I
had a problem not so long ago that i needed to build a solution to
render pages correctly depending on browser and OS, here is the code
from my work around.
browser_check.asp
<% '------------------Robbie Done 2008-------------------- '------------------www.bizmo.co.uk--------------------- 'Get Browser if instr(request.serverVariables("HTTP_USER_AGENT"),"MSIE")> 0 Then Session("svBrowser") = "ie" Else if instr(request.serverVariables("HTTP_USER_AGENT"),"Firefox")> 0 Then Session("svBrowser") = "firefox" Else if instr(request.serverVariables("HTTP_USER_AGENT"),"Safari")> 0 Then Session("svBrowser") = "safari" Else if instr(request.serverVariables("HTTP_USER_AGENT"),"Opera")> 0 Then Session("svBrowser") = "opera" End If End If End If End If
'Get OS if instr(request.serverVariables("HTTP_USER_AGENT"),"Macintosh")> 0 Then Session("svOS") = "osx" Else if instr(request.serverVariables("HTTP_USER_AGENT"),"Windows")> 0 Then Session("svOS") = "windows" End If End If %> <% 'Name Style Sheet Dim vBrowser,vOS,vFileName
vBrowser = Session("svBrowser") vOS = Session("svOS") vFileName = vBrowser&"_"&vOS&".css" If vFileName = "firefox_windows.css" Then vFileName = "style.css" End If %> <!-- Show default style sheet --> <link href="style.css" rel="stylesheet" type="text/css" media="screen"> <!-- Pick up amended browser/Os specific style sheet depending on browser and OS--> <%If vFileName <> "firefox_windows.css" AND vFilename <> "style.css" Then%> <!-- I always style for FireFox and Windows first and work on others secondly, so the statment above is basically saying that if the dynamic name is 'firefox_windows.css' then don't put a secondary sheet in but use style.css, but if it is a different browser/os then add the secondary sheet in --> <link href="<%=vFileName%>" rel="stylesheet" type="text/css" media="screen"> <%End If%>
Put this code in the head of your page and create the style combinations :-
- ie_windows.css
- firefox_osx.css
- opera_windows.css
- safari_windows.css
- safari_osx.css
There may be more file's than the list above but it is a good start.
One point is that some browsers will render the same or there abouts as
Firefox, so you will not necessarily need to create a separate sheet as
style.css will be fine for rendering.
You may also want to separate the operations into 2 files if you are going to use this on multiple pages.
inc_browser_check.asp
<% '------------------Robbie Done 2008-------------------- '------------------www.bizmo.co.uk--------------------- 'Get Browser if instr(request.serverVariables("HTTP_USER_AGENT"),"MSIE")> 0 Then Session("svBrowser") = "ie" Else if instr(request.serverVariables("HTTP_USER_AGENT"),"Firefox")> 0 Then Session("svBrowser") = "firefox" Else if instr(request.serverVariables("HTTP_USER_AGENT"),"Safari")> 0 Then Session("svBrowser") = "safari" Else if instr(request.serverVariables("HTTP_USER_AGENT"),"Opera")> 0 Then Session("svBrowser") = "opera" End If End If End If End If
'Get OS if instr(request.serverVariables("HTTP_USER_AGENT"),"Macintosh")> 0 Then Session("svOS") = "osx" Else if instr(request.serverVariables("HTTP_USER_AGENT"),"Windows")> 0 Then Session("svOS") = "windows" End If End If %>
a_dynamic_page.asp
Place in the <head></head> tags...
<% 'Name Style Sheet Dim vBrowser,vOS,vFileName
vBrowser = Session("svBrowser") vOS = Session("svOS") vFileName = vBrowser&"_"&vOS&".css" If vFileName = "firefox_windows.css" Then vFileName = "style.css" End If %> <!-- Show default style sheet --> <link href="style.css" rel="stylesheet" type="text/css" media="screen"> <!-- Pick up amended browser/Os specific style sheet depending on browser and OS--> <%If vFileName <> "firefox_windows.css" AND vFilename <> "style.css" Then%> <!-- I always style for FireFox and Windows first and work on others secondly, so the statment above is basically saying that if the dynamic name is 'firefox_windows.css' then don't put a secondary sheet in but use style.css, but if it is a different browser/os then add the secondary sheet in --> <link href="<%=vFileName%>" rel="stylesheet" type="text/css" media="screen"> <%End If%>
Hope you guys and girls can use this.....
|