How to use ASP to obtain the client screen resolution, we can achieve it in the following ways:
When accessing a web page, use js to get the resolution of the browser, then redirect to this web page and pass the resolution out, then receive the resolution and store it in the session, and finally redirect to the previous web page.
Code:
<%
'If it has automatically shifted to execute this conditional statement
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
%>
<%
'Visit the web page for the first time
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
%>
<%=Your resolution is: &session(MyScreenWidth)&*&session(MyScreenHeight)%>
<%
'The following are several functions
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
%>