Where do my visitors come from? That is always a question bloggers, site owners and advertisers want to know. Knowing who has referred the visitor to my site tells you a lot about that visitor. This information might help you drive better, more finely tuned content to this user.
document.write("Hello, Thank you for arriving from: " + document.referrer);
document.write("Hello, Thank you for arriving directly to this page");
This topic is covered in detailed in this interesting article.