Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnClick function doesnt fire on iframe? [closed]

I am trying to make click function fire when iframe is being clicked but It doesn't fire. Is it possible to do it ?

$("#iframe").click(function() {
alert("works");
});

<iframe id="iframe" src="http://site.com" scrolling="no"></iframe>
like image 343
user198989 Avatar asked May 28 '13 13:05

user198989


1 Answers

Another solution is to overlay a transparent div and add a click event to that div. Working sample: http://jsfiddle.net/w1ll3m/AxJHH/

<div class="container">
    <iframe src="#url"></iframe>
    <div class="overlay"></div>
</div>

css to position the div.overlay over the iframe:

.container{position:relative;float:left;}
.overlay{top:0;left:0;width:100%;height:100%;position:absolute;}

Add the event:

$('.overlay').click(function(){alert('hello');});
like image 124
Willem Avatar answered Oct 15 '22 15:10

Willem