Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
675 views
in Technique[技术] by (71.8m points)

javascript - window.postMessage to script.google.com as popup

When run: MyPopWindow.postMessage("Test", 'mydomaine'); I have a error on MyPopWindow whith script.google.com:

(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').

When run: MyPopWindow.postMessage("Test", 'https://script.google.com'); I have a error on MyPopWindow:

dropping postMessage.. was from host mydomaine but expected host https : // ******-script.googleusercontent.com

Source in page on 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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This error message comes from one of App Scripts Javascript driver files. This is extra security Google added on to prevent people from using the postMessage system.

It seems Google wants to force you to use one of their accepted protocols for communication between windows/domains, namely the Execution API. I have attempted other methods like passing URL parameters, but so far none have worked because I could not access them from within the iframe that all apps scripts run in.

I believe the Execution API is your best bet.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...