views:

112

answers:

3

Hi,

Is it possible to track a button click within an iFrame if i don't have control over the external website or it's contents?

(very fictionnal example)if i had an iframe like this:

<iframe src="http://www.johnny.com/plugins/like.php?href=http%253A%252F%252Fexample.com%252Fpage%252Fto%252Flike&amp;amp;layout=standard&amp;amp;show_faces=true&amp;amp;width=450&amp;amp;action=like&amp;amp;font&amp;amp;colorscheme=light&amp;amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>
A: 

Not reliably across browsers, no.

That would easily qualify as a cross site scripting (XSS) exploit and be caught by the majority of modern browsers.

Justin Niessner
+1  A: 

If you are asking whether you can find a button in the DOM of the HTML that has your iframe and then add an onclick event to it, then yes, if you are served from the same domain.

 window.parent.getElementById()

will work -- so will any other DOM functions.

If you are not on the same domain, then the browser won't let you. It's called cross-site scripting (XSS) and is considered a security violation.

If you are on another domain, the owner did add your iframe, right? If so, have them also add in the events. They can pass in variables and call helper functions on your iframe. So they could pass the button in and you could add the event to it.

Lou Franco
We are on one domain where we have installed an iFrame widget refering to another domain, so it's a case of XSS, understood.Would it be possible to add somekind of overlay (assuming we know the widget position on the page) to track the "onclick" event and to pass it to the iframe ?Unfortunately, we cannot ask the 3rd party widget provider to add anything to their iFrame.
PhilGo20
Here's the thing -- I hope not. XSS is a security violation for a reason. Should an ad be able to read my mail or trick me into doing something I can't see. If the site owner won't cooperate, anything you do should be stopped by the browser. If you find a way -- it's a security bug.
Lou Franco
+1  A: 

The answer is : not possible at all without some kind of cooperation with the remote site.
That is due to the Same Origin Policy kicking in for your protection.

If you have some kind of cooperation then you could pull this of using cross-domain messaging (eg. with easyXDM).

Sean Kinsey
thanks for the easyXDM link
PhilGo20