Hi all! I have been trying to find how to get the refering url to a page of my website, check if it's included on a txt file and then print a modal popup with a message. So, if you come from a friend url included on the txt it will welcomes you "You come from a friend's url" for example, and if not, then another msg will be printed. Someone knows? I have found codes for the different functions separately but don't know how to put them all together to do this. Thanks!
You need to use: var referrer = document.referrer; Code (markup): If you want to get the domain name use: var referrer = document.referrer.split('/')[2]; Code (markup):
Hi! thanks for answering. I think I would need something like this : <?php if (ref.match(/^https?:\/\/([^\/]+\.)?friendsite\.com(\/|$)/i)) { alert("You came from a friend Website"); else { alert("You came from a non friendly Webstie"); } ?> Code (markup): But this is just not working at all as it gives me a 500 error. Thanks for helping!
Don't wrap the code in PHP tags, it's JavaScript. <script> if (ref.match(/^https?:\/\/([^\/]+\.)?friendsite\.com(\/|$)/i)) { alert("You came from a friend Website"); } else { alert("You came from a non friendly Webstie"); } </script> Code (markup):