google-apps-scriptiframeweb-applications

Where is my iframe in the published web application/sidebar?


I've been running into various errors when trying to control the window in DOM of my published web app and addon sidebar.

After researching, I figured this is due to the web content being served in a iframe. The documentation doesn't show much except that the webapp is sandboxed in a iframe.

Relevant documentation I've researched:

Some of the relevant questions I've looked into:

My specific question is: Where exactly is my iframe window in the published web app or my add on sidebar?


Solution

  •               PUBLISHED WEB APP
    +---------------------------------------------+
    |              script.google.com              |
    |                                             |<------- [#0] window.top The top frame
    |                                             |
    |     +---------------------------------+     |
    |     |     *.googleusercontent.com     |<----+-------- [#1] Outer Sandboxed Iframe
    |     |         sandboxFrame            |     |
    |     |    +-----------------------+    |     |
    |     |    |        /blank         |    |     |
    |     |    |    userHtmlFrame      |    |     |
    |     |    |                       |    |     |
    |     |    |     Where the html    |<---+-----+-------- [#2] Inner Sandboxed Iframe
    |     |    |    file you created   |    |     |
    |     |    |       is loaded       |    |     |
    |     |    |                       |    |     |
    |     |    |                       |    |     |
    |     |    |                       |    |     |
    |     |    |                       |    |     |
    |     |    |                       |    |     |
    |     |    +-----------------------+    |     |
    |     |                                 |     |
    |     |                                 |     |
    |     +---------------------------------+     |
    |                                             |
    |                                             |
    |                                             |
    +---------------------------------------------+
    

    You're right. Most of the errors are due to the iframe sandboxing done by Google. To answer your question,

    Notes:

    With IFRAME mode however HTML forms are allowed to submit, and if a form element has no action attribute specified it will submit to a blank page. Worse, the inner iframe will redirect to the blank page before the onclick handler has a chance to finish.

    The solution is to add JavaScript code to your page that prevents the form elements from actually submitting, so that the click handlers have time to function


                SIDEBAR/MODAL DIALOG
    +---------------------------------------------+
    |              docs.google.com                |
    |  +--------------------------------------+   |<------- [#0] window.top The top frame
    |  |      /macros/.../iframedAppPanel     |<--+-------- [#1] Frame1 Same origin 
    |  |  +---------------------------------+ |   |
    |  |  |     *.googleusercontent.com     |<|---+-------- [#2] Outer Sandboxed Iframe
    |  |  |         sandboxFrame            | |   |
    |  |  |    +-----------------------+    | |   |
    |  |  |    |        /blank         |    | |   |
    |  |  |    |    userHtmlFrame      |    | |   |
    |  |  |    |                       |    | |   |
    |  |  |    |     Where the html    |<---+-|---+-------- [#3] Inner Sandboxed Iframe
    |  |  |    |    file you created   |    | |   |
    |  |  |    |       is loaded       |    | |   |
    |  |  |    |                       |    | |   |
    |  |  |    |                       |    | |   |
    |  |  |    |                       |    | |   |
    |  |  |    |                       |    | |   |
    |  |  |    |                       |    | |   |
    |  |  |    +-----------------------+    | |   |
    |  |  |                                 | |   |
    |  |  |                                 | |   |
    |  |  +---------------------------------+ |   |
    |  |                                      |   |
    |  +--------------------------------------+   |
    |                                             |
    +---------------------------------------------+
    

    All the above notes for web app stands true also for webcontent published using HtmlService in sidebar or modal dialogs. However,


    Changelog: