Take Away: Many users these days have very wide screens. This article shows you how to determine the browser width using ASP classic.
KB101299
Since websites and web browsers use a document type interface, webmasters have the challenging task of deciding what size document to target. Up until about 1999, many webmasters were designing their websites to look good on older 640x480 monitors. Because users accept scrolling vertically, many webmasters would design the home page to fit within 640x480 and the rest of the website would scroll vertically as needed. Around 2000-2001 many webmasters moved to an 800x600 common denominator and now in 2008, many websites target 1024x768. This article describes a technique for determining the width of the browser.
Our Prestwood family of websites use the full width of your monitor and we add content for extra wide monitors. The following are the code snippets we use to determine the width of your browser.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' A_GetBrowserWidth '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function A_GetBrowserWidth A_GetBrowserWidth = 0
If Len(Request.Cookies("BrowserWidth")) > 0 Then A_GetBrowserWidth = Number(Request.Cookies("BrowserWidth")) ElseIf Len(Session("BrowserWidth")) > 0 Then A_GetBrowserWidth = Number(Session("BrowserWidth")) Else A_GetBrowserWidth = 0 End If
A_GetBrowserWidth = Number(A_GetBrowserWidth) End Function
''Fix GetBroswer values if values above 0. '''''''''''''''''''''''''''''''''''''''''' If Number(Request.Cookies("BrowserWidth")) > 0 and Number(Session("BrowserWidth")) > 0 Then If Number(Request.Cookies("BrowserWidth")) < Number(Session("BrowserWidth")) Then Session("BrowserWidth") = Number(Request.Cookies("BrowserWidth")) ElseIf Number(Session("BrowserWidth")) < Number(Request.Cookies("BrowserWidth")) Then Response.Cookies("BrowserWidth") = Number(Session("BrowserWidth")) End If End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' WriteWidthJS ' ' You must call this from within the body tag. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub WriteWidthJS(AForceRefresh) Dim ForceRefresh
If UCase(AForceRefresh) = "YES" Then ForceRefresh = True Else ForceRefresh = False End If
If Not ForceRefresh and Len(Session("BrowserWidth")) > 0 Then ''' Do Nothing. ''' ElseIf Not ForceRefresh and Len(Request.Cookies("BrowserWidth")) > 0 Then Session("BrowserWidth") = Request.Cookies("BrowserWidth") Else %> <script type="text/javascript" language="javascript"> <!-- var JSBrowserW;
if (parseInt(navigator.appVersion)>3) { if (navigator.appName=="Netscape") { JSBrowserW=window.innerWidth; } if (navigator.appName.indexOf("Microsoft")!=-1) { JSBrowserW=document.body.offsetWidth; } }
var JSDate = new Date(); JSDate.setTime(JSDate.getTime()+(90*24*60*60*1000));
document.cookie="BrowserWidth=" + JSBrowserW + "; expires=" + JSDate.toGMTString(); // --> </script> <% If Len(Session("BrowserWidth")) = 0 and Len(Request.Cookies("BrowserWidth")) > 0 Then Session("BrowserWidth") = Request.Cookies("BrowserWidth") End If End If End Sub
Since websites and web browsers use a document type interface,
webmasters have the challenging task of deciding what size document to
target. Up until about 1999, many webmasters were designing their
websites to look good on older 640x480 monitors. Because users accept
scrolling vertically, many webmasters would design the home page to fit
within 640x480 and the rest of the website would scroll vertically as
needed. Around 2000-2001 many webmasters moved to an 800x600 common
denominator and now in 2008, many websites target 1024x768. This
article describes a technique for determining the width of the browser.