DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: HowTo retrieve a users Screen.Height???

  1. #1
    Rasmus Guest

    HowTo retrieve a users Screen.Height???


    Well,
    I wonder if it's possible to read a user's screen resolution from ASP.

    In the same way as you can with ex JavaScript
    <SCRIPT LANGUAGE="JAVASCRIPT">
    userScreenHeight = screen.height;
    </SCRIPT>

    I'm running VBScript in my asp-pages, and for some reason this code fails:
    <%
    DIM LinesPerPage
    LinesPerPage = 19

    IF Screen.Height = 600 THEN
    LinesPerPage = 13
    END IF
    %>

    And then when i out-comment the IF-block, the code runs without errors.


    Now please, Ladies or Gentlemens what should I test for in my IF-block??


    /Rasmus

  2. #2
    Russell Jones Guest

    Re: HowTo retrieve a users Screen.Height???

    You've confused server-side VBScript with client-side JScript. The server
    doesn't have access to the user's screen resolution unless you obtain it
    from the client and post it back. If you write the code as client-side code,
    it works fine:

    <script language="VBScript">
    userScreenHeight = screen.height
    </script>

    If you need to know the user's screen resolution on the client, try
    something like this. You can paste the code below into an empty ASP page.
    *********************************
    <%@ Language=VBScript %>
    <%
    ' GET or POST
    Dim IsPostBack
    If Session("ScreenX") = "" then
    ' if this page is a POST request then check to see
    IsPostBack = (Request.ServerVariables("REQUEST_METHOD") = "POST")
    if IsPostBack then
    if Request.Form("x") <> "" then
    Session("ScreenX") = Request.Form("x")
    Session("ScreenY") = Request.Form("y")
    end if
    else
    With Response
    .Write "<html><head></head><body>"
    .Write "<form id=""frmResolution"" name=""frmResolution""
    method=""post"">" & vbcrlf
    .Write "<input type=""hidden"" id=""x"" name=""x"">" & vbcrlf
    .Write "<input type=""hidden"" id=""y"" name=""y"">" & vbcrlf
    .Write "</form>" & vbcrlf
    .Write "<scri"
    .Write "pt language=""VBScript"">" & vbcrlf
    .Write "document.getElementById(""x"").value = Screen.Width" & vbcrlf
    .Write "document.getElementById(""y"").value = Screen.Height" & vbcrlf
    .Write "document.getElementById(""frmResolution"").submit" & vbcrlf
    .Write "</script>" & vbcrlf
    .Write "</body></html>"
    .End
    End With
    end if
    End If
    %>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>

    <P>Your screen resolution is <%=Session("ScreenX")%>,<%=Session("ScreenY")%>
    </P>
    </BODY>
    </HTML>
    *****************************************


    "Rasmus" <gojoe@bigfoot.com> wrote in message news:3c517bdc$1@10.1.10.29...
    >
    > Well,
    > I wonder if it's possible to read a user's screen resolution from ASP.
    >
    > In the same way as you can with ex JavaScript
    > <SCRIPT LANGUAGE="JAVASCRIPT">
    > userScreenHeight = screen.height;
    > </SCRIPT>
    >
    > I'm running VBScript in my asp-pages, and for some reason this code fails:
    > <%
    > DIM LinesPerPage
    > LinesPerPage = 19
    >
    > IF Screen.Height = 600 THEN
    > LinesPerPage = 13
    > END IF
    > %>
    >
    > And then when i out-comment the IF-block, the code runs without errors.
    >
    >
    > Now please, Ladies or Gentlemens what should I test for in my IF-block??
    >
    >
    > /Rasmus




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center