This is the code that you need to place in your default index page or any page for getting the referrer and redirect the user to "some_url". Replace the "some_url" with your own website link to redirect the user if the user is coming from Facebook or example domain names.
<script>
function getTheReferrer() {
var referrer = document.referrer;
if (referrer.indexOf('www.facebook.com') !== -1 || referrer.indexOf('www.example.com') !== -1) {
window.location.href = 'some_url';
}
}
window.onload = function() {
getTheReferrer();
}
</script>
If you want to try this here then follow the below steps -
The below content is STRICTLY for Developers
<script>
function getTheReferrer() {
var referrer = document.referrer;
if (referrer.indexOf('www.facebook.com') !== -1 || referrer.indexOf('www.example.com') !== -1) {
window.location.href = 'some_url';
}
}
window.onload = function() {
getTheReferrer();
}
</script>
If you want to try this here then follow the below steps -
- Go to Inspect Mode by clicking the button f12 on your keyboard or pressing CTRL+SHIFT+I key combination.
- Then inspect by clicking on the arrow symbol in the inspect window.
- Click on the "here" link on the bottom.
- Change the href attribute of the below anchor (<a>) tag to the url ("https://www.example.com") where you want the user to redirect.
- After changing the url to your desired one, click on that hyperlink.
- Now, you will be able to redirect to the URL you modified in the anchor (<a>) tag.
The below content is STRICTLY for Developers
Test the document referrer by changing the URL of this link in "Inspect Mode" and then by clicking here