From: Thomas 'PointedEars' Lahn on
Asen Bozhilov wrote:

> Csaba Gabor wrote:
>> How can I most reliably detect when a link has been clicked to open in
>> a new tab or to open in a new window? I have not found this question
>> well adressed in the pages returned up my searches.
>>
>> I am doing some statistics gathering. In particular, I have some
>> links that point to external websites (they are product links) and I
>> would like to know when they are clicked, to verify against what the
>> destination site reports. If they are clicked "normally", to open in
>> the same window, it is no problem because one just adds an onclick
>> handler to the link. All my onclick handler does is to send a request
>> out via an embedded Iframe (so it can be logged by the server), and
>> this request gets sent before the new page starts to load.
>
> One possible approach is server side proxy. If you detect click on
> link log statistic and request external page in iframe, otherwise
> request your page on same server. There will be server side script
> which log statistic and relocate to external page. In my opinion that
> is simple solution for your problem.

But HTTP proxying will not serve to detect if a new viewport was created to
view the referred resource. Nor can anything else, reliably.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
From: Asen Bozhilov on
Thomas 'PointedEars' Lahn wrote:
> Asen Bozhilov wrote:

> > One possible approach is server side proxy. If you detect click on
> > link log statistic and request external page in iframe, otherwise
> > request your page on same server. There will be server side script
> > which log statistic and relocate to external page. In my opinion that
> > is simple solution for your problem.
>
> But HTTP proxying will not serve to detect if a new viewport was created to
> view the referred resource.  Nor can anything else, reliably.

Of course, but is that really need? He just not able to detect it.
With suggested approach, if that resource is requested that mean a
resource has not been requested from him page after regular click on
link. I think he wants that. If he wants to detect opened new windows
there is something wrong. For example in Firefox extensions that is
possible by XPConnect but in browser scripting that is not possible,
especially when we talk about cross domain policy.
From: Evertjan. on
Csaba Gabor wrote on 21 jun 2010 in comp.lang.javascript:

>> Perhaps you could measure the old and new page witdhs and compare
>> those with the specified wondow.open() width?
>>
>> If the requested width is 20px, and the old and new witdh are both
>> the sa
> me
>> value and >250px, I would guess it is a tab.
>
> I like the brainstorming, but I don't think this is relevant here as
> there is no window.open() involved. Ie. a right click, open in new
> tab/window will open what is in href=..." in the relevant window, but
> not use a javascript window.open() to do so.

Use Chrome and on right-click you can choose.

But that is non of the buziness of the javascript writer to know or
manipulate on.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
From: Stefan Weiss on
On 21/06/10 16:18, Asen Bozhilov wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Asen Bozhilov wrote:
>> > One possible approach is server side proxy. If you detect click on
>> > link log statistic and request external page in iframe, otherwise
>> > request your page on same server. There will be server side script
>> > which log statistic and relocate to external page. In my opinion that
>> > is simple solution for your problem.
>>
>> But HTTP proxying will not serve to detect if a new viewport was created to
>> view the referred resource. Nor can anything else, reliably.
>
> Of course, but is that really need? He just not able to detect it.

I agree. That would be the solution I'd prefer if I had to log all link
clicks, even if the eventual target is an external page. I think that
was the OP's main point, instead of recognizing when a new tab (or
window) was opened.
If that was really important, it might be possible to use history.length
in some cases:

- let all external links point to a script on your site, for example
/tracker?t=http%3A%2F%2Fwww.example.com%2F

- if JavaScript is enabled, add an additional parameter to this link:
/tracker?t=http%3A%2F%2Fwww.example.com%2F&js=1

- in the 'tracker' script, log the link access and
a) without the 'js' parameter, redirect to the link target
b) with js=1, send back a small HTML document which reads
history.length, sends the result back to the server, and uses
history.replace() to direct the visitor to the target site. A
length of 1 would suggest that the link has been opened in a new
tab/window. You could use other indicators, like the 'Referer'
header, cookies, or an additional link parameter to distinguish
this case from links which were opened from bookmarks, or directly
entered in the address bar.

I don't recommend it. It's not going to work in all cases, and some
visitors may object (especially if you name the server side script
'tracker' ;-), but that's the only thing that comes to my mind if you
really really need to detect opened tabs.


--
stefan
From: Dr_Kral on
On Mon, 21 Jun 2010 02:13:23 -0700 (PDT), Csaba Gabor <danswer(a)gmail.com>
wrote in
<7260e06f-2666-41c7-afbb-c2a749613506(a)k39g2000yqb.googlegroups.com>:

>How can I most reliably detect when a link has been clicked to open in
>a new tab or to open in a new window? I have not found this question
>well adressed in the pages returned up my searches.
As explained by several posters already doing this client side is certainly
impossible on the face without JS allowed and you may not count on JS
being active (which would not help).

The answer is therefore you must do it server side.

If you can trust the clients, then making the link trigger a counter in
their server will do the job. You say you can do this.

Then you must do it in your own server. All the links point to your server
and then you redirect to the client's server. Or you can mirror the
client's pages in your server in some case for faster response.

K.