Search code examples
javascripthtmlgoogle-apps-scriptgoogle-apps-script-editor

How to set a link in Google Apps Script HTMLService? (error the conexion with accounts.google.com recused)


I'm tring to use the Apps Script method setContent() to add a link do a simple index.html file in Google Apps Script.

  var newDocLink = "https://docs.google.com/document/d/1loBt7T7-4qd0ORBXiTFeDQxuG..."; 
  // newDocLink variable have some Google Docs URL as value
  var output = HtmlService.createHtmlOutput('Click <a href= " '  + newDocLink + ' ">here to open the link in a new tab</a> a minuta')
  SpreadsheetApp.getUi().showModalDialog(output, 'My page title');

I get the link, but when I click on it, it doesn't work, showing this message "the conexion with accounts.google.com recused", in my language.

I know this is very simple, but I know very little of HTML and, after looking for similar questions, didn't find a solution or similar purpose code. Any help would be appreciate!


Solution

  • Issue:

    • You're trying to open a Google document inside a iframe, which Google docs doesn't allow.

    Solution:

    • Open it in a new tab by setting target attribute

      var output = HtmlService.createHtmlOutput('Click <a rel="noreferrer noopener" href= " '  + newDocLink + ' " target="_blank">here to open the link in a new tab</a>')
      

    References: