Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Google应用程序脚本获取用户输入,无长度限制_Google Apps Script - Fatal编程技术网

Google apps script Google应用程序脚本获取用户输入,无长度限制

Google apps script Google应用程序脚本获取用户输入,无长度限制,google-apps-script,Google Apps Script,我想使用以下任一方法获取用户输入(特别是HTML): var ui = SpreadsheetApp.getUi(); var response = ui.prompt('Paste HTML below'); 或 这些方法对于小的输入很有效,但是当复制感兴趣的页面的整个HTML时,会发生错误(在每种情况下)。无法捕获此错误,它只会使脚本崩溃。 你知道为什么会这样吗?我在文档中找不到任何提到输入大小限制的内容 有没有其他的经验 编辑:根据评论中的建议,我尝试了另一种方法(如下)。当传递大输入时

我想使用以下任一方法获取用户输入(特别是HTML):

var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Paste HTML below');

这些方法对于小的输入很有效,但是当复制感兴趣的页面的整个HTML时,会发生错误(在每种情况下)。无法捕获此错误,它只会使脚本崩溃。

你知道为什么会这样吗?我在文档中找不到任何提到输入大小限制的内容

有没有其他的经验

编辑:根据评论中的建议,我尝试了另一种方法(如下)。当传递大输入时,此操作也会失败(没有错误消息)

首先,我设置了
Page.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Paste Sitemap Content Below
    <textarea id="user-input-box" rows="4" cols="50"></textarea>
    <script>
      function logToConsole() {
        var userInput = document.getElementById("user-input-box").value;
        google.script.run.doSomething(userInput);
      }
    </script>
    <input type="button" value="Close" onclick="logToConsole();google.script.host.close();" />
  </body>
</html>

我只是遇到了同样的问题,无法记录错误。在我和你的例子中,你调用logToConsole()函数,然后直接在关闭对话框后使用google.script.host.close()

问题出在google.script.host.close()上。由于某些原因,它可能会取消脚本执行-这通常发生在您将大量数据发送回时。诀窍是在调用脚本时使用successHandler,然后脚本调用google.script.host.close()。这样,对话框中的数据传输将正确完成,当您使用SuccessHandler()调用时,该回调将关闭对话框。请尝试对您的代码进行以下修改:

<script>
    function logToConsole() {
        var userInput = document.getElementById("user-input-box").value;
        google.script.run.withSuccessHandler(closeDialog).doSomething(userInput);
    }

    function closeDialog() {
        google.script.host.close();
    }
</script>
<input type="button" value="Close" onclick="logToConsole()" />

函数logToConsole(){
var userInput=document.getElementById(“用户输入框”).value;
google.script.run.withSuccessHandler(closeDialog).doSomething(userInput);
}
函数closeDialog(){
google.script.host.close();
}

使用a似乎是一个自然的解决方案,表单可以有一个大的文本输入框,并在提交时调用脚本(在表单提交触发器上)使用自定义对话框:文本区域:@SandyGood如果我错了,请更正我,但它看起来像是您链接到我的自定义对话框使用了我已经尝试过的
ui.prompt
@Michelle我希望在这个项目的sheets应用程序中完全做到这一点,但知道这一点很好。谢谢你们两位的建议您需要查看文档中的“Page.html”选项卡。您没有使用该示例中的代码。该文档未使用
ui.prompt
,不幸的是,该文档中的图形具有误导性。阅读文档。你还没有读过。@SandyGood谢谢你提供的详细信息(并提醒我没有读过这些文件……我可能会很健忘)。我明白你现在的意思。要将数据发送回脚本,我发现非常有用
function testDialog() {
  var html = HtmlService.createHtmlOutputFromFile('Page')
      .setWidth(400)
      .setHeight(300);
  SpreadsheetApp.getUi()
      .showModalDialog(html, 'My custom dialog');
}

function doSomething(userInput){
  Logger.log(userInput);
}
<script>
    function logToConsole() {
        var userInput = document.getElementById("user-input-box").value;
        google.script.run.withSuccessHandler(closeDialog).doSomething(userInput);
    }

    function closeDialog() {
        google.script.host.close();
    }
</script>
<input type="button" value="Close" onclick="logToConsole()" />