Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript无法使用window.postMessage将消息发送到弹出窗口_Javascript_Html - Fatal编程技术网

Javascript无法使用window.postMessage将消息发送到弹出窗口

Javascript无法使用window.postMessage将消息发送到弹出窗口,javascript,html,Javascript,Html,弹出窗口中的事件不会触发,但实际数据始终为: {'messageId':0,'value':false} 在我的父窗口中: $('.myChatButton').click(function () { let params = 'resizable=no,width=1200,height=800'; var chatWindow = window.open('http://localhost/Support/Chat-Server', 'windowName

弹出窗口中的事件不会触发,但实际数据始终为:

{'messageId':0,'value':false}

在我的父窗口中:

  $('.myChatButton').click(function () {

       let params = 'resizable=no,width=1200,height=800';

       var chatWindow = window.open('http://localhost/Support/Chat-Server', 'windowName', params);

       try {
             chatWindow.postMessage('testMessage', "http://localhost/Support/Chat-Server");
        }
        catch (e) {
             console.log(e.message);
        }

   });
在我的弹出窗口中:

//窗口就绪功能:

   $(function () {
      // added once true because for some reason this event was fired 3 times when clicked to open pop-up
      window.addEventListener("message", receiveMessage, { once: true}); 
   });

    function receiveMessage(event) {        
        console.log(event.data);
    }

那个
事件.数据
来自另一个
postMessage()
调用。@Barmar哪个不同的postMessage()调用..我如何从调用窗口的窗口发送数据。请打开(…)到目标弹出窗口?它在代码中的某个地方,你还没有发布。您的代码发送一个字符串,但侦听器正在接收一个对象。用
messageId
@Barmar搜索你所有的代码,你说的很有道理,但我在父级和弹出窗口上都按CTRL-F键搜索索引页,却从未找到“messageId”变量。我确实为db crud操作设置了一个带有SignalR和web api的消息传递系统,但该特定变量名不存在。我还想知道这是从哪里来的……hotjar.com是一个网站分析服务。我的猜测是,当您创建一个弹出窗口并向其发送消息时,它会进行检测。