window.postMessage发送到script.google.com作为弹出窗口。

12 浏览
0 Comments

window.postMessage发送到script.google.com作为弹出窗口。

运行时:

MyPopWindow.postMessage("Test", 'mydomaine');

我在script.google.com的MyPopWindow中遇到错误:

(program):1 Failed to execute 'postMessage' on 'DOMWindow': The target

origin provided ('mydomaine') does not match the

recipient window's origin ('https://script.google.com').

运行时:

MyPopWindow.postMessage("Test", 'https://script.google.com');

我在MyPopWindow中遇到错误:

dropping postMessage.. was from host mydomaine but expected host

https : // ******-script.googleusercontent.com

mydomaine的页面上的源代码:

  window.addEventListener("DOMContentLoaded", function() {
    window.addEventListener("message", function(e) {
        // wait for child to signal that it's loaded.
        if ( e.data === "loaded" && e.origin === iframe.src.split("/").splice(0, 3).join("/")) {
            // send the child a message.
            alert(e.data);
        }
    })
}, false)

在作为WebApp运行的Google Apps Script上的源代码:

        document.addEventListener('DOMContentLoaded', function () {
            // signal the parent that we're loaded.
            window.parent.postMessage("loaded", "*");
            // listen for messages from the parent.
            window.addEventListener("message", function(e) {
            if(event.origin !== 'mydomain') return;
                  var message = e.data;
                  alert(message);
            }, false);
        });

0