我对脚本不太了解,但我正试图在谷歌单张上制作一个可点击的按钮,以超链接到另一个网站。出于某种原因,google不允许您超链接google绘图。:/
我知道如何分配脚本到按钮(也就是谷歌绘图插入我的谷歌表),但我不知道实际的脚本,将该按钮超链接到另一个网站。
任何帮助都将不胜感激!
发布于 2020-12-15 19:02:58
遵循以下步骤:
您的代码应该如下所示:
//change the value of url to your desired url.
function openUrl( url="https://stackoverflow.com/questions/10744760/google-apps-script-to-open-a-url" ){
var html = HtmlService.createHtmlOutput('<html><script>'
+'window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};'
+'var a = document.createElement("a"); a.href="'+url+'"; a.target="_blank";'
+'if(document.createEvent){'
+' var event=document.createEvent("MouseEvents");'
+' if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'
+' event.initEvent("click",true,true); a.dispatchEvent(event);'
+'}else{ a.click() }'
+'close();'
+'</script>'
// Offer URL as clickable link in case above code fails.
+'<body style="word-break:break-word;font-family:sans-serif;">Failed to open automatically. <a href="'+url+'" target="_blank" onclick="window.close()">Click here to proceed</a>.</body>'
+'<script>google.script.host.setHeight(40);google.script.host.setWidth(410)</script>'
+'</html>')
.setWidth( 90 ).setHeight( 1 );
SpreadsheetApp.getUi().showModalDialog( html, "Opening ..." );
}注意:可能无法在您的第一次运行,因为PopUp布洛克,允许站点和重新单击按钮。
https://stackoverflow.com/questions/65310335
复制相似问题