I've described a solution in a different comment on this thread. For each outbound link on the page, build a link that points to a redirector that accepts two query parameters: current page's canonical URL and outbound link's URL. The redirector will redirect the browser back to the canonical URL. Upon receiving the request for the canonical URL, instead of serving normal content, the server redirects the browser to the outbound link's URL on the condition that its referrer came from the redirector. This way, the outbound link gets the correct referrer without using any javascript wizardry. In fact, you can use this technique to customize the referrer to whatever you want.
http://a.com/redirect?canonical_url=http%3A%2F%2Fa.com%2Fpages%2F3&outbound_url=http%3A%2F%2Fb.com%2F
"canonical_url" is set to "http://a.com/pages/3"
"outbound_url" is set to "http://b.com/"
4. Redirector logs the request and redirects browser to canonical_url (i.e. "http://a.com/pages/3)
5. Code behind http://a.com/pages/3 checks the referrer to see if it came from the redirector.
5a. If it is, parse the outbound_url from the referrer URL and redirect the browser to that URL.
5b. If it isn't, serve normal content.
Basically, every content page needs to also act as a redirector and only redirects when the referrer indicates that the previous request came from the redirector.
This works by switching the url when a user clicks a link to your redirect url, then switching it back a fraction of a second after they mouse up. This means that your redirect works even if the user right clicks and opens in a new window / tab and when a user hovers over a link, they still see the normal URL in the status bar.
On the /redirect url just log any data you need and send a 301 or 302 redirect. The destination site will see your original page as a referrer, not your redirect url.
Are you referring to the fact that the browser will interrupt your tracking request because it already started loading the linked page? I haven't really tried, but I believe this can be dealt with if your server-side code expects it to happen.
1. Browser visits http://a.com/pages/3?privacy_leaking_param=1
2. User clicks on an outbound link: http://b.com/
3. Browser gets redirected to redirector at:
4. Redirector logs the request and redirects browser to canonical_url (i.e. "http://a.com/pages/3)5. Code behind http://a.com/pages/3 checks the referrer to see if it came from the redirector.
5a. If it is, parse the outbound_url from the referrer URL and redirect the browser to that URL.
5b. If it isn't, serve normal content.
Basically, every content page needs to also act as a redirector and only redirects when the referrer indicates that the previous request came from the redirector.