Ir1sh Ir1sh - 10 months ago 91
Javascript Question

Call controller from click within an iframe with angular

I am trying to bind an event to an iframe so that no matter where in the iframe is clicked, the event fires a function in the angular controller. I am trying to do this with just the jquery lite that ships with angular, or with pure javascript, whichever solution I happen across first.

I have been trying variations on this but not having any luck:

angular.element('iframe').contents().find('html').bind('click', function () {


Well, you can't go looking for elements out of the blue like normal jquery apps. you got to use a directive.

look here : plunker demo

In myDirective, i use the iframe element to do what you wanted:

app.directive('myDirective', function(){

  return {
    link : function(scope, element, attributes){
      element.contents().find('html').bind('click', function () {


You should also take some steps to ensure that the 'element' in the link function is an iframe.