Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-30-2012, 07:05 PM   PM User | #1
clicktrack
New to the CF scene

 
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
clicktrack is an unknown quantity at this point
regex to get referring domain

I am trying to check the referring domain and match certain domains and got part way there but not all of the way.

Ideally I want to check referrer and if it matches google, yahoo, bing, msn, etc. I want to get which one so I can change some stuff on the site for them.


So far I have something like this.
Code:
var url = document.referrer;
patternstring =  /^https?:\/\/(\w+\.)?(google|yahoo|msn)\./;
matcher = url.match(patternstring);
This will match but gives back more than I want. I would only want it to give back google or yahoo or msn.

Any help would be appreciated.
clicktrack is offline   Reply With Quote
Old 05-30-2012, 07:59 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
patternstring =  /^(https?:\/\/)(\w+\.)?(google|yahoo|msn)\./;
matcher = url.match(patternstring);
if (matcher !=null) {  // a match was found
alert (matcher[1]);  // http://
alert (matcher[2]);  // www.
alert (matcher[3]); // google or yahoo or msn
}

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 05-30-2012 at 08:11 PM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:55 PM.


Advertisement
Log in to turn off these ads.