views:

260

answers:

2

From within a browser extension (BHO) I want to know the URL that referred a user to the current page. I thought I could just get the document.referrer, but I find that's blank if links are opened in a new window. Is this just tough bikkies or can I use opener.location.href in some cases, or something else?

As a follow-up, I'm currently getting this when the page has loaded, ie on DocumentComplete, but I'd prefer to get it on BeforeNavigate2. I don't see any way to do that except use the current location as the referrer on BeforeNavigate2, however that will give me the current page as a referrer if users enter a new URL in the address bar. ie it'll look like they navigated from a link on site A to site B where actually they went to site A then typed in the url for site B.

UPDATE: From what I can tell, sometimes the 'opener' property will be set (if the window has been opened from javascript?) and therefore we can get the effective referrer page from that. Anyone know specifically in which situations this is available?

A: 

The only way to get this information is from the HTTP referrer, so unfortunately you may be out of luck for any situations in which that header value is blank.

Andrew Hare
so is that always blank for pages opened in a new tab/window?
Rory
A: 

Unless you owned the page that has the link to a new window, and add a hash or id or something identifying to a session or to the link, you will not be able to capture the referrer.

alex
so it's normal that links opened in a new window/tab get a blank referrer?
Rory
It's one way of getting a blank referer, but not the only way.
Joe