Refused to Connect Error while inserting Google Drive Link in HTML Services of Google API Script

1.1k views Asked by At

The code.gs has the following code.

function doGet() {

var output = HtmlService.createHtmlOutputFromFile('userendhtml');

output.addMetaTag('viewport', 'width=device-width, initial-scale=1');
return output;

}

The userendhtml has the following code.

<a href="https://drive.google.com/file/d/xxxxxxxx/view?usp=sharing">Lecture Notes</a>

The Google Drive Link refers to pdf file shared publicly. When user runs the script, The output is correct. However when he clicks on the link, he get the error that drive refused to connect. This works when I make the link with target =_"blank". I want to open pdf in same tab. How to solve this error? Can it be restructured in a way that back (browser back) will also work?

1

There are 1 answers

2
Amit Agarwal On

It is a known issue in Apps Script and likely happens when you are logged into multiple Google accounts.

Try the same app inside Chrome's incognito mode or log out of all other Google accounts and only log into the main Google account.