簡體   English   中英

在 iFrame 中嵌入 Google Apps 腳本

[英]Embedding Google Apps Script in an iFrame

我正在嘗試將使用 Google Apps Script 中的 Javascript 動態構建的頁面嵌入到 iFrame 中的我的網站中,但未顯示 iFrame 的內容。 Google Apps 腳本具有阻止加載的同源策略。

我想做的是(我刪除了完整鏈接):

<iframe src="https://script.google.com/a/macros/SCRIPT_ID"></iframe>

我得到的錯誤是:

Refused to display 'https://script.google.com/a/macros/SCRIPT_ID' 
in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

有沒有辦法更改策略並將內容加載到 iFrame 中?

谷歌最近剛剛啟用了這個功能。 很長一段時間以來,它一直處於“功能請求”狀態。 鏈接在這里

您現在可以明確定義 X-Frame-Options。

要允許在另一個域下嵌入,該選項應為 HtmlService.XFrameOptionsMode.ALLOWALL

有關該主題的 Google 文檔:

https://developers.google.com/apps-script/reference/html/html-output#setXFrameOptionsMode(XFrameOptionsMode)

示例:

function doGet() {
    return HtmlService.createTemplateFromFile('form.html')
        .evaluate() // evaluate MUST come before setting the Sandbox mode
        .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

希望這有幫助!

我在 doPost 響應表單上遇到了這個問題,僅在開發模式下,並通過在初始 doGet 表單上將 target="_self" 更改為 target="_top" 來糾正它。

 <form method="POST" id="ss-form" target="_top" action="<?!=SETTINGS.PUBLISHED_URL?>">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM