View Full Version : Search within a string

04-28-2006, 09:38 PM

I'm trying to determine if a referrer is from a domain.

So, for example, page http://sumeetjain.com/money.htm is linked to from http://sumeetjain.com/a.htm, http://sumeetjain.com/b.htm, and http://sumeetjain.com/c.htm.

I can do document.referrer; to grab the referrer to money.htm, but I just need to know if the referrer is from the domain sumeetjain.com. It doesn't matter if it's from a.htm, b.htm, or c.htm.

Is it possible to store the full referrer into a variable and then check if that variable's value begins with "http://sumeetjain.com" or if it contains "sumeetjain.com"? That check would let me know if it's from the domain.

Or if you can think of another way to accomplish this, that'd be great to. I appreciate any help you all can provide.



04-28-2006, 09:56 PM
You could use indexOf() or you could use Regular Expressions.


04-28-2006, 10:03 PM
Just remember that a lot of people have document.referrer disabled in their browser or firewall so that a lot of the time you will get blank passed instead of the address of the referrer page.

04-28-2006, 11:26 PM
Thanks for the help - both of you. The method worked perfectly, and I'll be sure to remember the limitations of the technology.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum