ASP獲取客戶端屏幕分辨率、ASP獲得用戶分辨率

字號:


    實現(xiàn)方法:
    在訪問網(wǎng)頁的時候使用js獲得瀏覽器的分辨率然后轉(zhuǎn)向本網(wǎng)頁并把分辨率傳出去,然后接收分辨率并把它存儲在session中,最后再轉(zhuǎn)到之前的網(wǎng)頁
    代碼:
    <%
    '若已經(jīng)自動轉(zhuǎn)向執(zhí)行此條件語句
    if Bint(trim(request("sw"))) > 0 then
       session("MyScreenWidth")=Bint(trim(request("sw")))
       session("MyScreenHeight") = Bint(trim(request("sh")))
       response.Redirect(session("FrontUrl"))
    end if
    %>
    <%
    '第一次訪問網(wǎng)頁
    if Bint(session("MyScreenWidth"))=0 then
    if Bint(trim(request("sw"))) = 0 then
       session("FrontUrl") = GetUrl()
    end if
    response.Write("<scr"&"ipt>")
    if Instr(GetUrl(),"?") > 0 then
       response.Write("window.location='"&GetUrl()&"&sw='+screen.width+'&sh='+screen.height;")
    else
       response.Write("window.location='"&GetUrl()&"?sw='+screen.width+'&sh='+screen.height;")
    end if
    response.Write("</scr"&"ipt>")
    end if
    %>
    <%="你的分辨率是:"&session("MyScreenWidth")&"*"&session("MyScreenHeight")%>
    <%
    '下面是幾個函數(shù)
    Function Bint(str)
    If IsNumeric(str) then
       Bint = Clng(str)
    Elseif IsEmpty(str) then
       Bint = 0
    Elseif IsNull(str) then
       Bint = 0
    Else
       Bint = 0
    End if
    End function
    Function GetUrl()
    sUrl = Request.ServerVariables("URL")
    sQueryString = ""
    For Each x In Request.QueryString
    sQueryString = sQueryString & "&" & x & "=" & Server.URLEncode(Request(x))
    Next
    if len(sQueryString)>0 then
    sQueryString = right(sQueryString,len(sQueryString)-1)
    else
    sQueryString = ""
    end if
    if len(sQueryString)>0 then
    GetUrl = sUrl & "?" & sQueryString
    else
    GetUrl = sUrl
    end if
    End function
    %>