将 URL 从 Google 脚本传递到 HTML 文件

我在传递我希望用户在单击侧边栏上的按钮时转到的 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 文件以供用户单击。


任何指导将不胜感激。


喵喵时光机
浏览 108回答 1
1回答

UYOU

回调函数.withSuccessHandler()将接收服务器函数返回的 url:客户端:<script>document.getElementById("btn").addEventListener("click",authorize);function callbackReceiver(url){//📞☎️&nbsp; alert(url);}function authorize(){&nbsp; &nbsp;google.script.run&nbsp; &nbsp; .withSuccessHandler(callbackReceiver)&nbsp; &nbsp; .authorizeSidebar();}</script>服务器端:function authorizeSidebar(){&nbsp; return getAuthorization()&nbsp; &nbsp; &nbsp; &nbsp; .getAuthorizationUrl();&nbsp; &nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript