Google Script App doesn´t work on Google Sites

727 views
Skip to first unread message

Nuno Marques

unread,
Dec 1, 2022, 12:05:36 PM12/1/22
to Google Apps Script Community
Hi.

I have made a App with multiple pages using google script and on App Script it works just fine.

But when i tryed to deploy it in google sites, it doesn´t work, the buttons don´t do nothing and using chrome´s debbuger console, it got this error

Unsafe attempt to initiate navigation for frame with origin 'https://sites.google.com' from frame with URL 'https://n-gg7ecyvi7l7wrakqmo537asyvznwrlxdefbzi5i-0lu-script.googleusercontent.com/userCodeAppPanel'. The frame attempting navigation of the top-level window is sandboxed, but the flag of 'allow-top-navigation' or 'allow-top-navigation-by-user-activation' is not set.

I search in internet for a solution to this issue and it seems that is related with iframe and sandbox features. But i couldn´t apply solutions on my code, i am doing something wrong and i am stucked on this.

Can you help me to solve this out?

You can see my code on the following link


Thank you for all the help.

cwl...@gmail.com

unread,
Dec 2, 2022, 10:23:31 AM12/2/22
to Google Apps Script Community
When you create your html file in your script, try adding some permissions (which seems to be the problem). For example, one of my pages:

function doGet(e) {
  var template = HtmlService.createTemplateFromFile('index');

  // Build and return HTML in IFRAME sandbox mode.
  return template.evaluate()
      .setTitle('My Dashboard')
      .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

Nuno Marques

unread,
Dec 3, 2022, 2:07:37 PM12/3/22
to Google Apps Script Community
Hi.

Thank you for your assistance.

I set  setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL); on my doGet code:

function doGet(e) {

  //Connect diferent web pages

  Route.path("form",loadForm);
  Route.path("table",loadTable);


  if(Route[e.parameters.v]) {
    return Route[e.parameters.v]();
  } else {
    var tmp = HtmlService.createTemplateFromFile("Home");
    return tmp.evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
  }
  
}

To configure the iframe, should i do it in the home-html page (it´s the main page of app) or should i create a new one with iframe to show home.html.

Thanks for all.
Message has been deleted

Nuno Marques

unread,
Mar 12, 2023, 2:19:27 PM3/12/23
to google-apps-sc...@googlegroups.com
Hi.

Ni i did not find :(

SCA Group <scagro...@gmail.com> escreveu no dia sábado, 11/03/2023 à(s) 10:33:
have u found the solution to this?
--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/P1EKPNlvx84/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/6418b655-10bc-47f1-8a13-7ec5b25db10dn%40googlegroups.com.

Michael O'Shaughnessy

unread,
Mar 12, 2023, 8:56:26 PM3/12/23
to google-apps-sc...@googlegroups.com
I don't have the answer but....

I have been successful with "multi page" webapps in sites by "fooling" the "end user".  What I do is each "page" I want to show is in it's own DIV.  What the page loads all DIVS are loaded BUT only 1 has it's visible property set to "visible".  All the others are "hidden".  Then all the button clicks are doing is hiding and unhiding the correct divs.  For all the things I need to do, this works for me.

Now, for standalone apps I am successful with using anchor elements and the scriplet to get the URL of the script.  They look like this:
<a href="<?= ScriptApp.getService().getUrl();?>?v=form">Form</a>
<a href="<?= ScriptApp.getService().getUrl();?>?v=about">About</a>

I tried a quick prototype of using an actual iframe element with the source set to my webapp then used the "embed" html on the google site BUT it didn't work... I might try to keep at it because this would really be a nice thing to be able to do!


You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAMaiGKFV6p_sDYhH5BdtSWxg_NxEcS-QVC0X9PG5Zp-OPKWNjw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages