html service for clickable link to open created PDF

120 views
Skip to first unread message

JC CANAULT - MSP Bellegarde

unread,
Jun 27, 2019, 7:34:28 AM6/27/19
to google-apps-sc...@googlegroups.com
Hello,

a friend of mine helped me to develop a script in a google sheet that creates a PDF from a spreadsheet. 
This pdf is aimed to be saved in google drive and the script works with a HTML files that creates a pop up with a clickable link to open and print the created PDF. 
The script works perfectly, all is created and saved at the right place, no problem

the link works but the problem i have is that recently when i click it doesn't open the file in a new tab anymore. i have to right click on it and choose open in a new tab. 

It's a problem because the sheet is used by other user that are not as experimented as me to pass over small ergonomical issues like this.

Anybody knows why the clickable link doesn't open a new chrome tab any more? here is the HTML file code.

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
     <a href="<?= body ?>" onblur="onBlur()">Click here to open and print</a>
     <script>
      function onBlur() {
        google.script.run.withSuccessHandler(close).resetDocOnClick();
      }
      function close() {
        google.script.host.close();
      }
    </script>
  </body>
</html>

Alan Wells

unread,
Jun 27, 2019, 9:35:51 AM6/27/19
to Google Apps Script Community
It's because of the target attribute setting:

<base target="_top">

It needs to be _blank. 

<base target="_blank">

You can override the setting in the HEAD tag, but putting a target attribute in the "A" tag itself also.

If you look in the console log, you may see an error when clicking the link.  Hit the f12 key in Chrome to open the developer tools in the browser.

I don't know why Apps Script insists on adding target="_top" to the HTML and then block all attempts to change the link in the same browser tab.

JC CANAULT - MSP Bellegarde

unread,
Jun 27, 2019, 10:43:49 AM6/27/19
to Google Apps Script Community
thanks! that made it... i don't get why it wasworking before and not anymore that's the question...
Reply all
Reply to author
Forward
0 new messages