简体   繁体   English

在侧边栏GAS中调用服务器端脚本

[英]Calling server-side script within a sidebar GAS

I am trying to call another sidebar within a different sidebar to create a sort of tabbed interface in google docs. 我试图在其他工具条中调用另一个工具条,以在Google文档中创建一种选项卡式界面。 I cannot figure out how to call the server-side function that displays the new sidebar within the html file of the present sidebar. 我无法弄清楚如何调用在当前工具条的html文件中显示新工具条的服务器端函数。

Here is my html sidebar button layout...(doesn't work) 这是我的HTML侧边栏按钮布局...(不起作用)

<div id='menu'>
    <button class="action" id="functions_nav">Functions</button>
    <button class="action" id="navbar">NavBar</button>
    <button class="action" id="settings" onClick="google.script.run.showSettings()">Settings</button>
  </div>

and my gs file... 和我的gs文件...

function showSettings() {
  var html = HtmlService.createHtmlOutputFromFile('settings')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setTitle('DebateDocs')
      .setWidth(300);
  DocumentApp.getUi() // Or DocumentApp or FormApp.
      .showSidebar(html);
}

The documentation on google deals with calling the buttons via "input type="button"..." however that will screw with my styling. Google上的文档涉及通过“ input type =“ button” ...”调用按钮,但是这会与我的样式有关。 Additionally they always call the scripts within javascript "script" tags. 另外,他们总是在javascript“ script”标签内调用脚本。 Is there some way I can route the button to a javascript event within the html file that points to the server? 有什么方法可以将按钮路由到指向服务器的html文件中的javascript事件?

Thanks for your help! 谢谢你的帮助! Any is appreciated. 任何赞赏。

your code is working fine for me. 您的代码对我来说很好。

The IFRAME Sandbox mode is new and has some bugs, try removing it or setting to NATIVE. IFRAME沙箱模式是新模式,存在一些错误,请尝试将其删除或将其设置为NATIVE。

Also please share if you can find any error if you see the execution transcript. 如果您看到执行记录,也发现任何错误,也请分享。

Cheers. 干杯。

PS: Sorry, I know this should be inserted as a comment, but don't yet have reputation to do so :( PS:对不起,我知道这应该作为注释插入,但是还没有信誉:(

You don't need to call the .gs script directly from a button. 您无需直接通过按钮调用.gs脚本。 You can use this configuration. 您可以使用此配置。

Button 按键

<div id='menu'>
  <button class="action" id="settings" onClick="fncShowSettings()">Settings</button>
</div>

HTML Script Tag HTML脚本标签

<script>
  window.fncShowSettings=function(){
    console.log("fncShowSettings ran");
    google.script.run
    .showSettings(); //Runs server side .gs function

</script>

Code.gs Code.gs

function showSettings() {
  Code here . . . 
  return someValue;
};

I'm not clear as to what you are asking, so if this doesn't help, just leave a comment. 我不清楚您要问什么,所以如果这样做没有帮助,请发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM