您的位置:首页 > 移动开发

解决 Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined.

2017-09-22 20:33 585 查看


在 issue 里并没有找到官方的解决办法:不过下面这段代码,就可以不在崩溃!

let getTitle: Function = function(url: string) {
setTimeout(function() {
// 防止postMessage崩溃
var originalPostMessage = window.postMessage;
var patchedPostMessage = function(
message: any,
targetOrigin: string,
transfer?: any[]
) {
originalPostMessage(message, targetOrigin, transfer);
};
patchedPostMessage.toString = function() {
return String(Object.hasOwnProperty).replace(
"hasOwnProperty",
"postMessage"
);
};
window.postMessage = patchedPostMessage;
window.postMessage(JSON.stringify({ title: document.title }), url);
}, 0);
};
let titleJs = "(" + String(getTitle) + ")();";


https://github.com/facebook/react-native/issues/10865#issuecomment-269847703
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐