Google Sites HTML Iframe (not gadget)

maeq picture maeq · Oct 13, 2014 · Viewed 8.8k times · Source

I'm trying to embed a google drive folder inside my google site, but this folder will be shown only to some users. That is why I can't use Insert --> Drive --> Folder.

I found at this post stackoverflow that you can show a specift folder using a HTML Iframe and It works perfectly.

Now I'm trying to embed that iframe on my Google Site with no luck. I've tried 3 different ways:

1) Using a HTML box (Insert --> HTML box)

This return the follow: removing disallowed attribute src on tag iframe

I used the exact same html code that works just fine

<iframe src="https://drive.google.com/embeddedfolderview?id=0B9xgK9AXrIuiMS0xNTQ5MzZjNy0xYTAxLTQzMjQtYWVkOS03M2Q3YWQxMzVhN2I#list" width="800" height="600" frameborder="0"></iframe>

2) Using the HTML service (Google Apps Script)

I create a Google Script that goes like this:

Code.gs

function doGet() {
  return HtmlService.createHtmlOutputFromFile('index');
}

index.html

<html>
  <body>
    <p>Hello Stackoverflow</p>
    <iframe src="https://drive.google.com/embeddedfolderview?id=0B9xgK9AXrIuiMS0xNTQ5MzZjNy0xYTAxLTQzMjQtYWVkOS03M2Q3YWQxMzVhN2I#list" width="800" height="600" frameborder="0"></iframe>
  </body>
</html>

This only shows the "Hello stackoverflow" and space where the iframe should be.

3) Insert --> More gadgets --> Include Gadget (iframe)

This one works with the same url that I used in the other methods: https://drive.google.com/embeddedfolderview?id=0B9xgK9AXrIuiMS0xNTQ5MzZjNy0xYTAxLTQzMjQtYWVkOS03M2Q3YWQxMzVhN2I#list

But this way is useless to me because I need to have control over which users can and can't see the Google Drive folder inside the Google Site.

Notice that it has nothing to do with http or https or the shield button on Google Chrome, because I'm using a https url.

Answer

Shiva picture Shiva · Apr 26, 2018

Try below Apps Script code

code.gs

    function doGet(e) {
    var template = HtmlService.createTemplateFromFile('Index');
    return template.evaluate()
    .setTitle('Web App Search Page')
    .setSandboxMode(HtmlService.SandboxMode.IFRAME)
    .addMetaTag('viewport', 'width=device-width, initial-scale=1')
    .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <iframe src="https://drive.google.com/embeddedfolderview?id=XXXXXXXXXX_FOLDERID_XXXXXX#list" width="800" height="600" frameborder="0"></iframe>
  </body>
</html>

Deploy as the web app and use "exec" link