9

I'm trying to integrate a google script app deployed as a web app in a Google Site. The embedding feature works well and all seems good at first. But for some reason links don't work in the embedded view. I can't find any specific topics about this.

Google Script web app can be embedded everywhere I tried except in Google Site. And Google Site can embed every site that allow it except web app from google script.

EDIT (2)

Turn out the problem can be resolved pretty quickly :

  1. Open https://sites.google.com and create a new site

  2. Insert an "embed" choose the "embed code" option and copy paste this code :

    <!DOCTYPE html>
    <html>
     <body>
       <div>
         <a href="http://google.com">Click Me!</a>
       </div>
     </body>
    </html>
    
  3. Now testing on preview or once the site publish the link can't be clicked

Rubén
  • 34,714
  • 9
  • 70
  • 166
Julien Maret
  • 579
  • 1
  • 4
  • 22
  • 1
    How do you have the link? Using a link with target="_blank" opens the link in another window:

    The link

    – Kessy May 27 '20 at 10:13
  • Don't work eigther. Links dont work like if they get they js .click() method rewrited to do nothing. – Julien Maret May 27 '20 at 10:31
  • 1
    Show errors in the chrome dev console – TheMaster May 27 '20 at 10:47
  • Well that is he funny part, my compagny desactivate the navigator dev tool.... – Julien Maret May 27 '20 at 10:56
  • Can you share the code or set up a reproducible example to see how are you doing it? – Kessy May 27 '20 at 14:03
  • Well i did @Kessy. you can take the code from the official google app script doc here : https://developers.google.com/apps-script/guides/html/restrictions#setting_the_link_target_attribute hten follow this: https://developers.google.com/apps-script/guides/web#deploying_a_script_as_a_web_app and then this : https://developers.google.com/apps-script/guides/web#embedding_a_web_app_in_new_sites – Julien Maret May 28 '20 at 05:34
  • 1
    Use [XFrameOptionsMode](https://developers.google.com/apps-script/reference/html/x-frame-options-mode) by changing the ``setSandboxMode`` for ``.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);`` – Kessy Jun 01 '20 at 14:31
  • 1
    I already try it. It dont seem like it chnage anything – Julien Maret Jun 02 '20 at 05:46
  • 1
    Show exact steps you did to embed the app in Google sites preferably with screenshots. – TheMaster Jun 02 '20 at 18:09
  • @TheMaster I edited it to make it more clear. Unfortunatly i'm unable to upload screenshots due to my compagnie policy. – Julien Maret Jun 03 '20 at 07:48
  • 1
    Does `_blank` work? and is it enough for you? The `allow-top-navigation` sandbox attribute is missing from Google sites embed feature. Therefore , I believe `_top` won't work. – TheMaster Jun 03 '20 at 12:01
  • 1
    It was like that in the google documentation, i forget to remove it. I use to dont put any target. But good news now i try to put `target="_self"` even if it suppose to be implicite and it seem to work :) – Julien Maret Jun 03 '20 at 12:32
  • It's google site embedding that want the target attibut to be specified other way they disable links aparently... – Julien Maret Jun 03 '20 at 12:39
  • I guess you lead me on the solution @TheMaster. Make an answer so i can validate it if you want – Julien Maret Jun 03 '20 at 12:40

2 Answers2

6

You have to specified the target propriety. Google script dont apply it by default so use this code :

<!DOCTYPE html>
<html>
 <body>
   <div>
     <a target="_self" href="http://google.com">Click Me!</a>
   </div>
 </body>
</html>
Julien Maret
  • 579
  • 1
  • 4
  • 22
0

FYI: I tried target="_self" and could not get it to work. The below is currently working for me. In our use we have the text link and an image as an icon for the href. Please note the scriplet is the URL. target="_blank" and with rel="noopener noreferrer" seems to have made the difference. I didn't delve too far into why but this article seemed to proved better explanation than other documentation I reviewed: https://pointjupiter.com/what-noopener-noreferrer-nofollow-explained/

<a target="_blank" href=<?=edGoogleDriveId?>><img src='google-drive.png'   alt="Google Drive icon" rel="noopener noreferrer" class='icon';/>Employee folder</a>
Doug Barense
  • 391
  • 3
  • 8