How to add click event to a iframe with JQuery -


i have iframe on page, coming 3rd party (an ad). i'd fire click event when iframe clicked in (to record in-house stats). like:

$('#iframe_id').click(function() {     //run function records clicks }); 

..based on html of:

<iframe id="iframe_id" src="http://something.com"></iframe> 

i can't seem variation of work. thoughts?

there's no 'onclick' event iframe, can try catch click event of document in iframe:

document.getelementbyid("iframe_id").contentwindow.document.body.onclick =  function() {   alert("iframe clicked"); } 

edit though doesn't solve cross site problem, fyi jquery has been updated play iframes:

$('#iframe_id').on('click', function(event) { }); 

update 1/2015 link iframe explanation has been removed it's no longer available.

note code above not work if iframe different domain host page. can still try use hacks mentioned in comments.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -