By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Combining Javascript and ASP question

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Brian wrote:
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)).

--
David Dorward <http://dorward.me.uk/>
Jul 20 '05 #2

P: n/a

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


"David Dorward" <do*****@yahoo.com> wrote in message
news:br*******************@news.demon.co.uk...
Brian wrote:
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)).

--
David Dorward <http://dorward.me.uk/>

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.