html - 将 URL 参数传递到 HTML 表单 Google Web App

标签 html google-apps-script web-applications url-parameters

我已经浏览了大部分与此相关的问题,但没有找到对我有帮助的解决方案(我已经一一应用了它们)。我有一个 HTML 表单,我正在通过 google 将其发布为网络应用程序。我需要用该参数预填充输入框。

代码.gs

function doGet() {
return HtmlService
        .createTemplateFromFile('html')
        .evaluate();      
          }

html.html

<!DOCTYPE html>
<html>
<head>
</head>
<style>
</style>
<body>
<form>
  <h1><center>Verification</center></h1>
  Form ID:<input type="number" name="formid" id="formid" class="formid">
</form>
</body>
</html>

正如我所说,我在类似问题中尝试了很多建议,但似乎找不到有效的建议。 id 是我可以输入我的 url + ?formid= 并将其填充在输入中。我怎样才能按照描述实现这一点?

谢谢!

最佳答案

  • 当使用 url + ?formid=### 的 URL 访问 Web Apps 时,您希望将 ### 的值放入文本框。
    • 网址类似于 https://script.google.com/macros/s/###/exec?formid=###

如果我的理解是正确的,这个答案怎么样?请将此视为多个答案之一。

修改点:

  • 在此修改中,我使用 google.script.url.getLocation() 来检索查询参数。

修改后的脚本:

请修改html.html如下。

<!DOCTYPE html>
<html>
<head>
</head>
<style>
</style>
<body>
<form>
  <h1><center>Verification</center></h1>
  Form ID:<input type="number" name="formid" id="formid" class="formid">
</form>
<script>
  google.script.url.getLocation(function(location) {
    document.getElementById("formid").value = location.parameters.formid[0];
  });
</script>
</body>
</html>
  • 通过上述修改,当您使用 https://script.google.com/macros/s/###/exec?formid=12345 访问网络应用时,12345 被放入文本框。

引用:

如果我误解了您的问题并且这不是您想要的方向,我深表歉意。

关于html - 将 URL 参数传递到 HTML 表单 Google Web App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58757625/

相关文章:

php - 动态数据驱动的用户界面

html - CSS 菜单在 iOS 上的 Safari 中不同,在 Firefox 和 IE 中正常

javascript - 正则表达式在 Javascript 中查找未知字符串并更改大小写

web-applications - 防止在比赛中进行多次投票

javascript - 使用 javascript 的 3d 立方体形状

html - 即使加载了 js,Bootstrap 崩溃也不起作用

javascript - 使用正则表达式从 html 页面获取所有链接

javascript - 以创建者用户身份单击按钮时运行函数 - Google 电子表格

java - 什么 PHP 框架与 Apache Wicket 最相似?

c++ - 使用什么 Web 服务/接口(interface)?