Here's an example:
HTML
<body onload="onload()">
<a href="defaultlink.html" id="theLink">Link</a>
</body>
JavaScript
<script type="text/javascript">
function onload() {
if (document.referrer) {
// gets full URL, ex: http://www.site.com/directory/1/2/index.html
url = document.referrer;
// just gets the domain, ex: www.site.com
ref = url.match(/:\/\/(.[^/]+)/)[1];
// alert for testing
alert(ref);
// if the ref equals what you want, then change the link href below to the alternate link
if (ref == 'www.google.com') {
var link = document.getElementById('theLink')
link.href = 'alternatelink.html';
}
}
}
</script>
In this example, if they come from www.google.com, the link will be updated to the alternatelink.html. Otherwise, it goes to the default link.