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

capture a URL

P: 2
I'm putting together a feedback form, and would like to 'capture' the URL of the previous page as part of the feedback. Can anybody help me with this?
Jan 31 '08 #1
Share this Question
Share on Google+
5 Replies


harshmaul
Expert 100+
P: 490
Hi,
There is a javascript object that will do that for you...

you can try

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3. if (document.referrer&&document.referrer!="")
  4.   document.write(document.referrer);
  5. -->
  6. </script>
Didn't have time to test it exactly but you can just google that object and thats what you need.
Jan 31 '08 #2

P: 2
Thanks Harsh, I give it a try
Feb 1 '08 #3

gits
Expert Mod 5K+
P: 5,333
hi ...

you should avoid document write when the page is loaded since it 'destroys' the document ... you could fill a hidden field onload of the form-page with the referrers value:

Expand|Select|Wrap|Line Numbers
  1. function init_fields() {
  2.     var n = document.getElementById('my_ref_hidden_field');
  3.     n.value = document.referrer;
  4. }
and call that function onload of you document:

[HTML]<body onload="init_fields();">[/HTML]
it assumes that you have a hidden input-field with an id called 'my_ref_hidden_field' ...

kind regards
Feb 1 '08 #4

harshmaul
Expert 100+
P: 490
Hi again,
I agree with gits, don't document write it out. i only document wrote it to show you where the variable was stored in the DOM.
Feb 1 '08 #5

gits
Expert Mod 5K+
P: 5,333
Hi again,
I agree with gits, don't document write it out. i only document wrote it to show you where the variable was stored in the DOM.
hi ...

i know ... just wanted to point it out to avoid those document.write() 'errors' in case the OP wouldn't be aware of it ... you gave the correct hint regarding the referrer that basicly is the thing the OP was looking for :)

kind regards
Feb 1 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.