I need grab the path of a referring URL, which can be served from many different hostnames which can be under HTTP or HTTPS and even have port numbers.
Can someone give me an example of how to run some code only if the referring URL contains a specific string such as path and a file name or just a certain path without a file extension?
Well, you can start with something simple:
var parts = document.referrer.replace(/^https?:\/\//, '').split('/');
parts.shift();
var path = parts.join('/');
if (path.indexOf('filename') > -1) {
// code here
}
And if you need more flexibility see this library: http://blog.stevenlevithan.com/archives/parseuri