码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2017-09-22 22:47:23      阅读:555      评论:0      收藏:0      [点我收藏+]

标签:exist   set   efi   没有   native   href   alt   .post   images   

技术分享

 

在 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

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

标签:exist   set   efi   没有   native   href   alt   .post   images   

原文地址:http://www.cnblogs.com/zhangyang17/p/7577037.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!