PDA

View Full Version : Emailing the entry page URL


Jay Vincent
05-06-2003, 06:40 PM
Hello everyone,

I would like to have a form that when emailed to me displays the first URL the browser used to enter my site.

For example, if a person entered a site at www.website.com/business/ then when the person filled in a contact form on a different page it would send me the entrance site URL 'www.website.com/business/'

Thanks for your help in advance

Jay Vincent

HairyTeeth
05-06-2003, 07:33 PM
A session-only cookie perhaps.

Two functions here. The setCookie() function should go in an external *.js file and be accessed by every page on the site:

function setCookie(){
if(document.cookie == ""){
var entryValue = location.href;
document.cookie="entryPoint="+entryValue;
}
}
onload=setCookie;


The getCookie() function should only be used on the page with the form.

function getCookie(){
var cField = document.cookieForm.cookieVal;
if(document.cookie){
if(document.cookie !="")
cField.value = document.cookie.split("=")[1];
}else if(!document.cookie){
cField.value="Cookies Unavailable";
}
}

where:
- formNAME is the name of the form;
- fieldName is the name of the field that you want to hold the cookie value (eg. a hidden field).
Call the getCookie() function with the onload event handler in the body tag.
This should work but I haven't really tested it.

[EDIT: I've changed the getCookie() function slightly to reflect a user with cookies turned off but still js enabled]

Jay Vincent
05-06-2003, 09:20 PM
Thanks Hairy Teeth! but I'm having a bit of trouble calling on the script on the contacts page and displaying the entry URL in a text field. Could you help me out with the form?

HairyTeeth
05-06-2003, 09:31 PM
<html>
<head>
<title>Contact Page</title>

<script type="text/javascript">
<!--;
function getCookie(){
var cField = document.cookieForm.cookieVal;
if(document.cookie){
if(document.cookie !="")
cField.value = document.cookie.split("=")[1];
}else if(!document.cookie){
cField.value="Cookies Unavailable";
}
}
//-->
</script>
</head>
<body onload="getCookie()">

<form name="cookieForm">
<input type="text" size="60" value="" name="cookieVal" />
</form>

</body>
</html>