我在传递我希望用户在单击侧边栏上的按钮时转到的 URL 时遇到问题。 <body> <p class="header">First we need to Authorize.</p> <button class="center waves-effect waves-light btn" id="btn">Authorize</button> <script> document.getElementById("btn").addEventListener("click",authorize); function authorize(){ google.script.run.authorizeSidebar(); } </script> </body>我在 GS 上的代码是:function authorizeSidebar(){var Authservice = getAuthorization(); var authorizationUrl = Authservice.getAuthorizationUrl(); //Logger.log(authorizationUrl); }我能够在第二个函数上输出我需要的 URL,但是我很难将它从 GS 文件传递到 HTML 文件以供用户单击。任何指导将不胜感激。
1 回答
UYOU
TA贡献1878条经验 获得超4个赞
回调函数.withSuccessHandler()将接收服务器函数返回的 url:
客户端:
<script>
document.getElementById("btn").addEventListener("click",authorize);
function callbackReceiver(url){//📞☎️
alert(url);
}
function authorize(){
google.script.run
.withSuccessHandler(callbackReceiver)
.authorizeSidebar();
}
</script>
服务器端:
function authorizeSidebar(){
return getAuthorization()
.getAuthorizationUrl();
}
添加回答
举报
0/150
提交
取消
