links from app scripts not working when embedded in Google sites

1,317 views
Skip to first unread message

Michel Parmentier

unread,
Nov 9, 2021, 4:32:26 PM11/9/21
to Google Apps Script Community
Hey scripters !
I need help integrating app scripts into a google sites.
I can't find a way to make links work that are coming from embedded scripts.
I'm developping a small site with a few pages plus register/login.
The scripts are fairly sophisticated (for me, lol), with encoding forms to Sheets and several datatables : everythings works well ! Except ...
Except I can't find how to make links work when they are built in script (plain or constructed).
I made a small test site, 3 pages ; 2 links on the home page, coming from a script.
Script and site accessible to anyone.
The google site :
- dev : https://sites.google.com/d/1UO3JDnWz_eO1HfKar4sfmfHD0MZQzPOT/p/1m0TtmyfD2rXVJKpX50sKEdOPK18HKGOx/edit
- published : https://sites.google.com/view/links-check/home
The script URL : https://script.google.com/macros/s/AKfycbwRovETx7YvWncp-tAb8nmQiF-Ipzt9oJ5B_F-YJIxTImYSmoE/exec
The script : https://script.google.com/d/1gD6OX-sanFCUDMUjB6CDPgsnty_UHL0KyGUoYnEqXNKf_VvYV4PRD8JO/edit?usp=drive_web&folder=1gEQB2V9trvib3VjQ6UGZ8zpBEybeo3J8&splash=yes

Clark Lind

unread,
Nov 10, 2021, 7:54:04 AM11/10/21
to Google Apps Script Community
For all the links you want to open in the same window, back to basics... lol     simply remove target="_self".  

Clark Lind

unread,
Nov 10, 2021, 9:10:23 AM11/10/21
to Google Apps Script Community
Because of the sandboxing that Google does with scripts,  to open a new window, you can try something like this:

<a onclick= "window.open('https://sites.google.com/view/links-check/thirdpage', '_blank','scrollbars=1')">Javascript Example</a>

you could add some css to the html <head> to make the link obvious:
<style>
.link {
   color: blue;
   text-decoration: underline;
}
</style>
<a class="link" onclick= "window.open('https://sites.google.com/view/links-check/thirdpage', '_blank','scrollbars=1')">Javascript Example</a>

Michel Parmentier

unread,
Nov 11, 2021, 7:37:38 AM11/11/21
to Google Apps Script Community
Thanks for your answer.

Yes, target = "_blank" opens a new window.No, removing target = "_self" doesn't open in the same window (that's what I would like). => I added a link with no target for you to test.
I also tested all links while having removed <base target="_top"> from the head section, just in case : same problem.
I just want them to open in the same window.

Michel Parmentier

unread,
Nov 11, 2021, 7:40:26 AM11/11/21
to Google Apps Script Community
same window and same tab, just as you would expect from a standard app/ web site.

Clark Lind

unread,
Nov 11, 2021, 8:47:57 AM11/11/21
to Google Apps Script Community
lol  OMG... doh!    you have been doing too much development I think. Your url has a typo. You have thirdPage  and it should be thirdpage  (not camelcase) ;)

This works for me:
   <div>
     <a href="https://sites.google.com/view/links-check/thirdpage">Click Me!</a>
   </div> 

Clark Lind

unread,
Nov 11, 2021, 8:51:39 AM11/11/21
to Google Apps Script Community
p.s.,  I was laughing at myself, not you. I hope that wasn't offensive.

Michel Parmentier

unread,
Nov 11, 2021, 2:23:12 PM11/11/21
to Google Apps Script Community
not offensive at all ! You can make a fool out of me, provided you help me find the solution :-)
However, it still doesn't work !  :-(
I changed the page names to all lower case as well as the links, I can't see no difference on my test page (script updated, page updated).

Clark Lind

unread,
Nov 11, 2021, 5:04:23 PM11/11/21
to google-apps-sc...@googlegroups.com
haha  ;)
How are you embedding your script link in the site?   Change your html file by removing everything in the body, and paste just this one div into the body:

   <div>
     <a href="https://sites.google.com/view/links-check/thirdpage">Click Me!</a>
   </div> 
--
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/gnTXzSaTL9k/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/c6b6c5d5-a872-4405-9553-2de1f9b8c50cn%40googlegroups.com.

Michel Parmentier

unread,
Nov 11, 2021, 5:24:11 PM11/11/21
to Google Apps Script Community
not sure I understand : remove everything from the body of the embedded file ? or from the Google sites ?

Michel Parmentier

unread,
Nov 11, 2021, 5:28:43 PM11/11/21
to Google Apps Script Community
https://sites.google.com/view/copy-link-checks/home
new test site with :
- one section with the whole GAS url embed
- one section below it with code pasted in the embed area

Michel Parmentier

unread,
Nov 11, 2021, 5:49:59 PM11/11/21
to Google Apps Script Community
I changed the first section as per your instruction now, replacing all the body content with you div code (first isolated "Click Me" link.
Doesn't work
Reply all
Reply to author
Forward
0 new messages