Reputation: 3820
i'm trying to track click on html element.
with:
$('html').click(function() {
// action here
});
but this thing won't work with iframe , coudn't catch iframe click, or click to selectionbox
Upvotes: 0
Views: 1956
Reputation: 16448
This answer is based on the iframe content is of your domain, using jquery 1.7.2 and this should be inside of document ready
html
<iframe id="myframe" src='/'></iframe>
js
$('#myframe').contents().find('body').bind('click', function(e) {
alert('clicked');
});
Upvotes: 3
Reputation: 461
You could place a div with a high z-index over the iframe. That should intercept all clicks and call the document click handler. The major issue is just that though. It intercepts all clicks so the underlying iframe will not receive any click events.
Upvotes: 0
Reputation: 526
You need to place your script inside the document.ready function, and change 'html' to document.
$(document).ready(function() {
$(document).click(function(e) {
alert("click");
});
});
Upvotes: 1