I am trying to return a value depending on which is the previous page the user came from.
I have looked at PHP with $_SERVER['HTTP_REFERER']
but this is no longer supported.
I have looked at JavaScript with
function sourcePrevious(){
if (document.referrer.search('https?://(.*)google.([^/?]*)') === 0) {
return 'Google';
} else if (document.referrer.search('https?://(.*)yahoo.([^/?]*)') === 0) {
return 'Yahoo';
} else if (document.referrer.search('https?://(.*)bing.([^/?]*)') === 0) {
return 'Bing';
}else if (document.referrer.search('https?://(.*)facebook.([^/?]*)') === 0) {
return 'Facebook';
}else {
return 'Other';
}
}
alert(sourcePrevious());
Which works in part, for Google, Yahoo & Facebook its working but for Bing and Twitter this is not the same case.
Can anyone point me in a direction of a method to do this or let me know how to get the JavaScript function to work for all sources.
Thanks!
答案 0 :(得分:0)
我解决了TWITTER问题
(document.referrer.search('https?://(.*)t.([^/?]*)') === 0)