Combining Javascript and ASP question

B

Brian

Hi All,

Can someone please point me in the right direction I am having problems
combining JS and ASP. What I am trying to do is store in a database using
ASP the referring page of my visitors. I got the ASP working great and when
I use the document.referrer in an alert it works too, but when I try to
combine the 2 languages that is when I get an error that I cannot fix. Here
is the code fragment that is not working:

rs("ReferPage") = %> document.referrer <%

I have tried this as well :

rs("ReferPage") =%> <script language="javascript"
document.referrer></script> <%

Both the code fragments are embedded in the head of the asp page hence the
%> and <%.

I am probably missing something very basic but I am at a loss to think what
it could be. I have done some searching and could not find a suitable
tutorial. The only one I found talked about using an include file. Any
help would be welcomed.

Brian
 
D

David Dorward

Brian said:
Can someone please point me in the right direction I am having problems
combining JS and ASP. What I am trying to do is store in a database using
ASP the referring page of my visitors. I got the ASP working great and
when I use the document.referrer in an alert it works too, but when I try
to
combine the 2 languages that is when I get an error that I cannot fix.
Here is the code fragment that is not working:

rs("ReferPage") = %> document.referrer <%
I am probably missing something very basic but I am at a loss to think
what it could be.

ASP is a means of executing scripts on the server, JavaScript (in this
usage) is a client side language. The ASP runs on the server, the
JavaScript runs on the client. The direction of communication is from the
server to the client, not the other way round. To get data from JavaScript
to the server you have to make a new HTTP request containing the data.

Its a big was of time trying to do that for this though - as the referer
information is already exposed to ASP anyway (although I'll point out that
the referer header is optional so the browser doesn't have to provide it -
and some personal firewalls obscure the referer in the interests of privacy
(why they don't just discard it I don't know, malformed http requests help
nobody)).
 
B

Brian

Hi David,

Thank you for your response. From your feedback I went and did another
search online to look for an ASP solution and I changed my code to read :

refer= Request.ServerVariables("HTTP_REFERER")

That was it and it is working perfectly.What a relief. I am branching out
into creating more dynamic pages with Javascript and am making mistakes
along the way. I posted the above code to help anyone else who might be in
the same situation. I see too often someone with a cool problem and then
they simply post "Thanks I found the answer and it works great" or
something like that. LOL It doesn't help the rest of us out. I am using an
older book that I bought real cheap by Coriolis and it didn't have the
HTTP_REFERER as part of the Server Variables Collection. I guess I better
get out and look for a better reference too.

Thanks for the push in the right direction.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,237
Latest member
AvivMNS

Latest Threads

Top