polaatx
asked on
Trying to combine ASP and javascript to pick up clientside screen resolution
Hi,
I am bouncing my pages off of the following code to try to pickup the screen resolution of the user in javascript and then bounce back to the referring page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H TTP_REFERE R") %>
<script language="javascript">
res = "&res="+screen.width+"x"+s creen.heig ht+"&d="+s creen.colo rDepth
top.location.href=RefPage& "?"&res
</script>
However, the javascript is not recognizing the RefPage variable. What am I doing wrong?
(disclaimer: I know almost nothing about javascript).
I am bouncing my pages off of the following code to try to pickup the screen resolution of the user in javascript and then bounce back to the referring page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H
<script language="javascript">
res = "&res="+screen.width+"x"+s
top.location.href=RefPage&
</script>
However, the javascript is not recognizing the RefPage variable. What am I doing wrong?
(disclaimer: I know almost nothing about javascript).
actually try this instead
top.location.href="<%=RefP age%>?"+re s;
havent got a webserver here so i cant test it sorry :)
Cheers
Scott
top.location.href="<%=RefP
havent got a webserver here so i cant test it sorry :)
Cheers
Scott
ASKER
Hi Scott,
I'm still getting a refpage undefined error.
Here's what I'm trying to do:
This code will be on top of every page of my site:
<%
if Session("screenres") <> "" then
response.Redirect("detects creen.asp" )
else
Session("screenres") = request.QueryString("res")
end if
%>
My logic is that if session("screenres") is not present yet, then redirect to detectscreen.asp, which contains just the following code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H TTP_REFERE R") %>
<script language="javascript">
res = "&res="+screen.width
top.location.href="<%=RefP age%>?"+re s;
</script>
Detectscreen.asp picks up the client's screen width, puts it in a querystring and bounces back to the referring page.
Then the referring page creates Session("screenres") = request.QueryString("res") and I should have the client's screen size from then on.
What do you think I'm doing wrong?
I'm still getting a refpage undefined error.
Here's what I'm trying to do:
This code will be on top of every page of my site:
<%
if Session("screenres") <> "" then
response.Redirect("detects
else
Session("screenres") = request.QueryString("res")
end if
%>
My logic is that if session("screenres") is not present yet, then redirect to detectscreen.asp, which contains just the following code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H
<script language="javascript">
res = "&res="+screen.width
top.location.href="<%=RefP
</script>
Detectscreen.asp picks up the client's screen width, puts it in a querystring and bounces back to the referring page.
Then the referring page creates Session("screenres") = request.QueryString("res")
What do you think I'm doing wrong?
Hi
try changing the function to this
<script language="javascript">
res = "res="+screen.width
top.location.href="<%=RefP age%>?"+re s;
</script>
notice the & has been removed from res = "&res
if that doesnt work try adding
alert("<%=RefPage%>?"+res) ;
before the top.location line and post back here what the alert says
cheers
scott
try changing the function to this
<script language="javascript">
res = "res="+screen.width
top.location.href="<%=RefP
</script>
notice the & has been removed from res = "&res
if that doesnt work try adding
alert("<%=RefPage%>?"+res)
before the top.location line and post back here what the alert says
cheers
scott
ASKER
Scott:
I changed the code to this:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H TTP_REFERE R") %>
<script language="javascript">
res = "res="+screen.width
top.location.href="<%=RefP age%>?"+re s;
</script>
And for some reason the page starts bouncing back to itself over and over, eventhough I was careful to go to it from another page so it would have referrer to go bounce back to.
For alert, this code ...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H TTP_REFERE R") %>
<script language="javascript">
res = "res="+screen.width
alert("<%=RefPage%>?"+res) ;
</script>
produces this: ?res=1024
So the querystring is good. But can't figure out why it doesn't record the referrer correctly.
I changed the code to this:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H
<script language="javascript">
res = "res="+screen.width
top.location.href="<%=RefP
</script>
And for some reason the page starts bouncing back to itself over and over, eventhough I was careful to go to it from another page so it would have referrer to go bounce back to.
For alert, this code ...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H
<script language="javascript">
res = "res="+screen.width
alert("<%=RefPage%>?"+res)
</script>
produces this: ?res=1024
So the querystring is good. But can't figure out why it doesn't record the referrer correctly.
hmm how about hardcoding just to test.
Set the RefPage = to the name of the page it is coming from.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = "nameofsubmittingpage.asp" %>
<script language="javascript">
res = "res="+screen.width
alert("<%=RefPage%>?"+res) ;
</script>
this will tell us if there is a problem with request.ServerVariables("H TTP_REFERE R")
Scott
Set the RefPage = to the name of the page it is coming from.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = "nameofsubmittingpage.asp"
<script language="javascript">
res = "res="+screen.width
alert("<%=RefPage%>?"+res)
</script>
this will tell us if there is a problem with request.ServerVariables("H
Scott
ASKER
It produces:
nameofsubmittingpage.asp?r es=1024
nameofsubmittingpage.asp?r
looks like a problem with
request.ServerVariables("H TTP_REFERE R")
i will have a look
request.ServerVariables("H
i will have a look
ASKER
Scott, It is working now. When I click a URL to detectscreen.asp, it is bouncing back to any page that refers to it with "res" value in querystring. Try it here: http://www.aurafellows.net/aura/mail_sample.htm and you will get back a querystring.
The problem I think was this code on top of the referring page I built to try to detect session variable:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
if Session("screenres") = "" then
response.Redirect("detects creen.asp" )
else
Session("screenres") = request.QueryString("res")
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<BODY>
<p><a href="detectscreen.asp">Go to detectScreen.asp</a><p>
screen resolution request querystring variable = <% = request.QueryString("res") %><br>
screen resolution session variable = <% = Session("screenres") %>
</BODY></HTML>
Right now, if the session variable is present, detectscreen.asp goes into a perpetual self-bouncing.
If the session variable is NOT present, the body does not show me the value of neither the session or the querystring.
The detectscreen.asp code is this now:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H TTP_REFERE R") %>
<script language="javascript">
res = "res="+screen.width
top.location.href="<%=RefP age%>?"+re s;
</script>
The problem I think was this code on top of the referring page I built to try to detect session variable:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
if Session("screenres") = "" then
response.Redirect("detects
else
Session("screenres") = request.QueryString("res")
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<BODY>
<p><a href="detectscreen.asp">Go
screen resolution request querystring variable = <% = request.QueryString("res")
screen resolution session variable = <% = Session("screenres") %>
</BODY></HTML>
Right now, if the session variable is present, detectscreen.asp goes into a perpetual self-bouncing.
If the session variable is NOT present, the body does not show me the value of neither the session or the querystring.
The detectscreen.asp code is this now:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% RefPage = request.ServerVariables("H
<script language="javascript">
res = "res="+screen.width
top.location.href="<%=RefP
</script>
Well spotted there pol :)
we might now need to think about some code to only add the res to the querystring if its not there already AND to maintain anyother existing querystring parameters
scott
we might now need to think about some code to only add the res to the querystring if its not there already AND to maintain anyother existing querystring parameters
scott
ASKER
How about this?
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
RefPage = request.ServerVariables("H TTP_REFERE R")
if request.QueryString("res") <> "" then
response.Redirect(RefPage)
else
%>
<script language="javascript">
res = "res="+screen.width
top.location.href="<%=RefP age%>?"+re s;
</script>
<% end if %>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
RefPage = request.ServerVariables("H
if request.QueryString("res")
response.Redirect(RefPage)
else
%>
<script language="javascript">
res = "res="+screen.width
top.location.href="<%=RefP
</script>
<% end if %>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what if add
if querystring("query")<>999 then
top.location.href="<%=RefP age%>?"+re s+"&query= "+<%=999%> ;
end if
if querystring("query")<>999 then
top.location.href="<%=RefP
end if
for the javascript to recognise the refPage variable you have to enclose it in the <%=RefPage%> tags to in your code
<script language="javascript">
res = "&res="+screen.width+"x"+s
top.location.href=<%=RefPa
</script>
Give that a go
Scott