How to embed HTML Service in other sites with iframe

Asked 2 years ago, Updated 2 years ago, 44 views

Create a template HTML in Google Apps Script and display it in doGet.Is it possible to specify the URL of the script in iframe and view it from other sites?

index.html

<html>
<body>
    <?
    varsite=sitesApp.getPageByUrl("https://sites.google.com/...");
    varcontents=site.getHtmlContent();
    output.append(contents);
    ?>
</body>
</html>

code.gs

function doGet(){
    varhtml=HtmlService.createTemplateFromFile("index");
    return html.evaluate;
}

google-apps-script

2022-09-30 12:01

1 Answers

I don't think I can do it at the moment.
X-Frame-Options can be used to prevent web pages from being embedded in iframes on other sites.
If you try to create and access HTML services, you will see the response header

X-Frame-Options:SAMEORIGIN

was included, the app script seems to have various security considerations, and it is also restricted.
There may be conditional permission eventually, and there may already be a way to remove the restriction, but the document does not seem to mention it.

You can embed it in Google Sites, so you want me to do it with that.

Note:
You can remove the X-Frame-Options restrictions on sites created by Google Sites in the Google Sites.
Therefore, the Google Sites page itself can be embedded in pages in other domains with iframe.
However, the HTML service embedded in it is still X-Frame-Options:SAMEORIGIN.

The reason why it can be embedded in Google Sites is because HTML services embedded in Google Sites are delivered from the sites.google.com domain, not from script.google.com.
This avoids restrictions on X-Frame-Options:SAMEORIGIN.

This causes the Google Sites portion to appear in the "Google Sites with HTML Services embedded page" and the HTML Services portion to not appear in it.

(These circumstances change from hour to hour, so I don't know how long this will last.Just in case)


2022-09-30 12:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.