在日常开发中,经常出现在新开tab页操作完毕后,发送消息更新其他页面的数据。 在此记录一下,以作参考
发送消息
window
.postMessage({
action
: 'refresh'
}, '*');
接收消息
window
.addEventListener('message',function(e
){
console
.log(e
);
var _action
= e
.data
.action
|| '';
switch(_action
){
case 'refresh':
console
.log('接受到用户发送的消息');
break;
}
})
转载请注明原文地址:https://ipadbbs.8miu.com/read-14092.html