BUTTON 发送消息 selectButton.addEventListener('click', () => { iframe.contentWindow.postMessage({ event_id: "select_media", return_type: 'media' }, '*'); }); const callBack = (e: any) => { if (e.data.selected_medias && e.data.selected_medias.length > 0) { 取消监听 (window as any).removeEventListener('message', callBack, false); } } 监听 const openIframe = () => { (window as any).addEventListener('message', callBack, false); ... }
标签:postMessage,removeEventListener,any,callBack,addEventListener,监听 From: https://www.cnblogs.com/zscxy/p/18023331