IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

Advanced
-Collapse +Expand ASP Classic Store

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...ASP ClassicLanguage Basics   Print This     
  From the February 2016 Issue of Prestwood eMag
 
ASP Classic Language Basics:
Get Browser Width
 
Posted 16 years ago on 10/16/2008
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.


Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1153A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101299 Counter
11501
Since 10/16/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]