<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.
I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!
<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.
Bookmarks