0.0.1 • Published 1 year ago

ajaxframe v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Iframe 通信插件

Parent

	let Iframe = document.getElementById('iframe');
	let af = new AjaxFrame(Iframe.contentWindow);
	// 监听 Iframe send/request
	af.listen('事件名称',(reg)=>{
		console.log(reg);
		return '返回的结果';
	});
	// 向 Iframe 发送需要回复的事件
	// timeout = 0 永不超时
	af.request('事件名称','data || ()=>any',timeout).then(reg=>{
		console.log(reg)
	}).catch(err)=>{
		// 没什么作用 超时后会来这里
	};
	// 向 Iframe 发送不需要回复的事件
	af.send('事件名称','data || ()=>any');

	// 取消监听
	af.unlisten('事件名称');

Child

	let af = new AjaxFrame(window.parent);
	// 监听 Parent Window send/request
	af.listen('事件名称',(reg)=>{
		console.log(reg);
		return '返回的结果';
	});
	// 向 Parent Window 发送需要回复的事件
	// timeout = 0 永不超时
	af.request('事件名称','data || ()=>any',timeout).then(reg=>{
		console.log(reg)
	}).catch(err)=>{
		// 没什么作用 超时后会来这里
	};
	// 向 Parent Window 发送不需要回复的事件
	af.send('事件名称','data || ()=>any');
	// 取消监听
	af.unlisten('事件名称');
0.0.1

1 year ago