打开链接的Google脚本

问题描述 投票:0回答:1

我尝试使用 Google 脚本打开链接,但超链接目标文本不可见

我尝试使用以下代码,但未显示超链接文本

function testNew(){
  showAnchor('Google','http://Www.google.com');
}

function showAnchor(name,url) {
  var html = '<html><body><a href="'+url+'" target="Google" onclick="google.script.host.close()">'+name+'</a></body></html>';
  var ui = HtmlService.createHtmlOutput(html)
  SpreadsheetApp.getUi().showModelessDialog(ui,"Google")
}
google-apps-script hyperlink
1个回答
0
投票

如果您想查看链接而不是超链接中的名称,则需要在 html 变量中替换它。 试试这个代码:

function testNew() {
  showAnchor('https://www.google.com');
}

function showAnchor(url) {
  var html = '<html><body><a href="'
    + url + '" target="Google" onclick="google.script.host.close()">'
    + url + '</a></body></html>';
  var ui = HtmlService.createHtmlOutput(html);
  Logger.log(html);
  SpreadsheetApp.getUi().showModelessDialog(ui, "Google")
}

© www.soinside.com 2019 - 2024. All rights reserved.