Передать переменную из родительского (мой домен) в iframe (Google Script) - PullRequest
0 голосов
/ 05 марта 2019

Я пытался найти способ передать переменную из родительского URL в дочерний iframe (скрипт Google).

Я использовал метод Post message, но он не работал, ошибка:

удаление postMessage .. было с хоста https: // .... но ожидаемый хост https://n -...... script.googleusercontent.com

мой код похож на ниже

Родительский код (JS):

window.onload = function() {
  // Get the window displayed in the iframe.
  var receiver = document.getElementById('Frame').contentWindow;

  // Get a reference to the 'Send Message' button.
  var btn = document.getElementById('send');

  function sendMessage(e) {
    // Prevent any default browser behaviour.
    e.preventDefault();

    receiver.postMessage('my message', 'https://script.google.com');
  }

  // Add an event listener that will execute the sendMessage() function
  // when the send button is clicked.
  btn.addEventListener('click', sendMessage);
}

также я пытался использовать полную ссылку на скрипт Google вместо 'https://script.google.com' receiver.postMessage('my message', 'full google script link');

HTML-код скрипта Google

window.onload = function() {
  // Get a reference to the div on the page that will display the
  // message text.
  var messageEle = document.getElementById('message');

  // A function to process messages received by the window.
  function receiveMessage(e) {
    // Check to make sure that this message came from the correct domain.
    if (e.origin !== "my domain")
      return;

    // Update the div element to display the message.
    messageEle.innerHTML = "Message Received: " + e.data;
  }

  // Setup an event listener that calls receiveMessage() when the window
  // receives a new MessageEvent.

  window.addEventListener('message', receiveMessage);
}

после сотен поисковЯ нашел поток, связанный с передачей сообщения от дочернего элемента (скрипт Google) на родительскую обычную HTML-страницу с помощью Google Execution API, но не могу понять, как это работает

, если есть какое-либо отношение к сообщению или другомуспособ передать простую переменную из моего домена (обычная HTML-страница) в скрипт Google (iframe) на той же странице ....

Пожалуйста, помогите !!!

...