如何用ASP取得客戶端螢幕分辨率,我們可以透過以下方式實現:
在訪問網頁的時候使用js獲得瀏覽器的分辨率然後轉向本網頁並把分辨率傳出去,然後接收分辨率並把它存儲在session中,最後再轉到之前的網頁
代碼:
<%
'若已經自動轉向執行此條件語句
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
%>
<%
'第一次造訪網頁
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)%>
<%
'下面是幾個函數
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
%>