1

so, my URL is example.com/?ref=person

but ref is null after the regex. What am I doing wrong here?

function getReferer(){
 var regex = new RegExp(/ref=(.+)/);
 var ref = regex.exec(window.location.ref);
 alert(ref);
 if (ref == null) return "";
 else return ref[1];
}
asked Aug 30, 2010 at 16:13

1 Answer 1

1

Replace window.location.ref by window.location.href. Don't use new RegExp if not necessary, it's slower.

function getReferer(){
 var regex = /ref=(.+)/;
 var ref = regex.exec(window.location.href);
 alert(ref);
 if (ref == null) return "";
 else return ref[1];
}
answered Aug 30, 2010 at 16:21
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.