Google Apps 脚本打开一个基于单元格的 URL
Google Apps Script to open a URL based on a cell
我有一个单元格 B2,它根据用户的选择显示动态 hyperlinks,我想将该单元格用作我的脚本的引用(在按钮上打开 url) .
如何修改此脚本以便从 B2 单元格获取 link?
//change the value of url to your desired url.
function openUrl( url="https://google.com" ){
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 ..." );
}
来自I would like to use that cell as a reference to my script (which opens url on a button).
和How can I modify this script in order to get the link from the B2 cell?
,当你的脚本被修改时,下面的修改如何?
发件人:
function openUrl( url="https://google.com" ){
收件人:
function openUrl(){
var url = SpreadsheetApp.getActiveSheet().getRange("B2").getValue();
参考文献:
我有一个单元格 B2,它根据用户的选择显示动态 hyperlinks,我想将该单元格用作我的脚本的引用(在按钮上打开 url) . 如何修改此脚本以便从 B2 单元格获取 link?
//change the value of url to your desired url.
function openUrl( url="https://google.com" ){
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 ..." );
}
来自I would like to use that cell as a reference to my script (which opens url on a button).
和How can I modify this script in order to get the link from the B2 cell?
,当你的脚本被修改时,下面的修改如何?
发件人:
function openUrl( url="https://google.com" ){
收件人:
function openUrl(){
var url = SpreadsheetApp.getActiveSheet().getRange("B2").getValue();