views:

117

answers:

3

I have an iframe that references an external URL that serves up pages that contain Flash adverts.

I need to track how often a customer clicks on one of those adverts.

The approach I am taking is to render a div element over the iframe. This allows me to intercept the click event, however I need to pass that click down to the iframe. Is this possible using JavaScript?

+2  A: 

No, it's not possible. You can't simulate a real click in javascript, you can only fire click events.

Andy E
And even if one could, it would not work because of Cross Domain Policy.
Pekka
That's what I had feared...
Richard Ev
A: 

I do not think that it is possible as well

But, assuming that the clicks redirect the user to the site of the advert, you could intercept the user click using redirections. Change the link to some script on your own server with some unique advert id. Register the click and redirect the user to the advertisement page.

Another possibility is to use this technique to load the contents of the iframe, so you known the amount of customers viewed the advertisement. But this of course might be an advertisement scheme your advertisement customer does not like/want.

Veger
A: 

You can't pass the click through by any legitimate means, and you'll run up against cross-domain problems if you tried to fake it in anyway. And I would definitely stay away from anything that looks like a clickjacking solution - it's bound to stop working (and feels evil too).

You may be able to hack something, depending on how accurate it has to be. This would involve tracking the sequence of events happening when user has put their mouse into the banner area and then left the page (inferring that they clicked on the ad). You'll miss some, and you may catch some false positives too.

It would work something like:

  1. Leave the covering div in place
  2. onMouseOver, hide the div and set an onbeforeunload event handler that registers a "click" through an AJAX post (or similar)
  3. when the mouse moves out of the banner area it means they didn't click the ad, so show the div again and remove the event handler

I'd guesstimate you'd get about 80-90% accuracy, but you're going to have to test on a lot of browsers. It's also assuming the ad loads into the same window and not a new one. If it loads into a new one then I think it's going to be even harder.

Karl B