This is iframe observer. Be Able to use it when you need get frame states or event listeners.
You need to add polyfill script if your browser is not support es6.
bower install frame-observer
npm install frame-observer
index.html
var iframe = document.querySelector('iframe');
var promise = frameObserver.callMethod( iframe, "info", {a:3} );
promise.then(function(){
console.log( arguments );
});
frame.html
frameObserver.registerMethods({
info:function( promise ){
promise.resolve(1);
}
});
listen a state from frame, promise will be trigger when state is resolved or rejected.
var iframe = document.querySelector('iframe');
frameObserver
.readyState( iframe, 'ready' )
.then(function(){
console.log('ready state:done...');
},function(){
console.log('ready state:fail...');
});
trigger a state for resolve.
frameObserver.resolveState('ready');
trigger a state for reject.
frameObserver.rejectState('ready');
listen a event from frame.
var iframe = document.querySelector('iframe');
frameObserver.on( iframe, 'iframeClicked', function(){
console.log('iframe clicked');
});
unregister a event from frame.
frameObserver.off( iframe, 'iframeClicked', iframeClicked );
implement some methods for other iframes. The method inputs will inject
promise
andparameters
.
frameObserver.registerMethods({
hello:function(promise, parameter1, parameter2 ...){
console.log('hello by self');
}
});
call a method of iframe or parent.
var promise = frameObserver.callMethod( iframe, "hello", {a:3} );
promise.then(function(){
console.log( arguments );
});
trigger a event
frameObserver.trigger( 'clicked' );
get a el context
frameObserver.getContext(iframe);
listen a event from context.
unregister a event from context.
listen a state from context.
call a method of context.
get a element from context.
npm run dev
npm run build
npm run test