javascript - Iframe with external URL, document click not working -


i trying document click on iframe, seems not picking document click event, tried generate iframe click explicitly, seems working internal content when put external url not firing click event,

html

<iframe id="myframe" src="http://kooldotnet.blogspot.in/2013/07/image-resize.html"></iframe> 

jquery

$('#myframe').load(function(){   $(this).contents().find("body").on('click', function(event) { alert('test'); }); }); 

sample code

please how should it

update

when tried in jsfiddle ifram src www.google.com working.

modifying code @a. wolf

i got following fiddle

mouseenter working not click

thanks

due same origin policy, cannot bind event content of cross domain iframe (if not explecitely handled iframe itself).

regarding specific case, binding click event iframe's body, maybe use workaround:

$(focuswindow);  $('iframe').on('mouseenter', function () {     window.targetediframe = this;     $(window).on('blur', iframeclicked); }).on('mouseleave', function () {     $(window).off('blur', iframeclicked);     if($(document.activeelement).is('iframe'))         focuswindow(); });  function iframeclicked(){     console.log('iframe clicked', window.targetediframe); }  function focuswindow(){     $('<div/>').attr('tabindex',-1).appendto('body').focus().remove(); } 

-jsfiddle-


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -