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.
-
Can you elaborate on how you want the controller to access the functions, and what specifically you're trying to do?whatoncewaslost– whatoncewaslost2015-07-03 01:23:00 +00:00Commented 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 everyonegaryM– garyM2015-07-03 01:32:57 +00:00Commented Jul 3, 2015 at 1:32
Add a comment
|
1 Answer
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
1 Comment
garyM
Hi dshun... Thanks for the example... I'll let you know in a bit :)