用户访问电子表格并请求应用程序创建提案(这是一个 Google 幻灯片应用程序)。电子表格使用 Google 脚本执行此操作。用户希望在不关闭原始电子表格的情况下立即打开并查看提案。我知道我可以问他们是否愿意使用 ui.alert 打开提案。我知道如何打开新提案,但我不知道如何将焦点放在屏幕上或将控制权转移给它。
任何人都可以帮忙吗?
要开始演示,您必须编写脚本以在演示模式下打开演示文稿。为此,您必须先构建 URL:
const presentation = SlidesApp.getActivePresentation();
const url = `https://docs.google.com/presentation/d/${presentation.getId()}/present`;
然后,您可能会打开一个对话框或侧边栏,其中包含客户端代码以打开 URL,就像使用任何 URL 一样。为此,您可以使用Stephen's answer to Google Apps Script 中的函数 openURL 来打开 URL:
/**
* Open a URL in a new tab.
*/
function openUrl( 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 ..." );
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句