I need JS on the page to check if the referrer is the previous page from the same domain.
The URL of the JS page is formatted as follows:
http://subdomain.site.com/dir/page?vs=123456
There may be several previous pages. Therefore, JS needs to verify domain matching.
If the domain is different, I want to send the user to another page.
Here is what I tried to work:
var matchHost = /^https?:\/\/.*\//; var match = matchHost.exec(document.referrer); var domain = "http://subdomain.site.com/dir/"; if (match !== domain) { window.location.href = domain; }
But not quite working.
Any ideas?
source share