用戶訪問電子表格并請求應用程式創建提案(這是一個 Google 幻燈片應用程式)。電子表格使用 Google 腳本執行此操作。用戶希望在不關閉原始電子表格的情況下立即打開并查看提案。我知道我可以問他們是否愿意使用 ui.alert 打開提案。我知道如何打開新提案,但我不知道如何將焦點放在螢屏上或將控制權轉移給它。
任何人都可以幫忙嗎?
uj5u.com熱心網友回復:
要開始演示,您必須撰寫腳本以在演示模式下打開演示文稿。為此,您必須先構建 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 ..." );
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/464918.html
