0

I'm trying to have an angularjs controller access javascript functions in a non-angularjs iframe. I don't know where to start. Looking for guidance.

2
  • Can you elaborate on how you want the controller to access the functions, and what specifically you're trying to do? Commented Jul 3, 2015 at 1:23
  • OK,, This was a generic question for the most part.. But, I want to use CesiumJs in an iframe and drive it from an angualrjs app.. CesiumJS is a 3Dmap viewer with hundreds of APIs to call, listing each one I want to use is a bit overwhelming for everyone Commented Jul 3, 2015 at 1:32

1 Answer 1

1

normally to communicate with an iFrame is to use window.postMessage, which enables cross-origin communcation, and on the receiving end, in your case, the window which has your angular code, you can use angular.element($window).on("message", function() to do whatever you want.

angular.module('windowExample', [])
.controller('ExampleController', ['$scope', '$window', function($scope, $window) {

  angular.element($window).on("message", function(e){
                    alert(e.data);
    }); 
}]);

A sample js fiddle is the following. Obviously I cannot really use an iFrame, so i used a button to fake the message

http://jsfiddle.net/atozaxsv/22/

Let me know

Sign up to request clarification or add additional context in comments.

1 Comment

Hi dshun... Thanks for the example... I'll let you know in a bit :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.