React Native webView postMessage报错

报错如下:
Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined.


React  Native  webView postMessage报错
IMG_2306.PNG

解决方法:

(function() {
          var originalPostMessage = window.postMessage;
        
          var patchedPostMessage = function(message, targetOrigin, transfer) { 
            originalPostMessage(message, targetOrigin, transfer);
          };
        
          patchedPostMessage.toString = function() { 
            return String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage'); 
          };
        
          window.postMessage = patchedPostMessage;
     //业务代码  
          $("#header").hide();
          $(".consultBtn").click(function(){
            window.postMessage("gochat")
          })
        })();
上一篇:JS中我用到的setInterval


下一篇:React native 栈溢出错误maximum call stack size exceeded.