Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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
Javascript 如何将Clipboard.js库导入Google应用程序脚本?_Javascript_Google Apps Script_Clipboard.js - Fatal编程技术网

Javascript 如何将Clipboard.js库导入Google应用程序脚本?

Javascript 如何将Clipboard.js库导入Google应用程序脚本?,javascript,google-apps-script,clipboard.js,Javascript,Google Apps Script,Clipboard.js,由于谷歌应用程序中禁止操作剪贴板,我想通过使用clipboard.js库找到一个解决方法 我的问题是: 1。如何将Clipboard.js库导入Google应用程序脚本? 2。以及如何调用其他页面中的函数(例如,尝试从index.html中的BMI.gs调用calculatewight()函数? 我所尝试的: 我尝试将Clipboard.js的源代码粘贴到一个名为Clipboard.js.html的文件中,并将所有内容都放在标记中 我想要达到的目标: 单击“复制”按钮复制文本字符串 我花了几个

由于谷歌应用程序中禁止操作剪贴板,我想通过使用clipboard.js库找到一个解决方法

我的问题是:

1。如何将Clipboard.js库导入Google应用程序脚本?

2。以及如何调用其他页面中的函数(例如,尝试从index.html中的BMI.gs调用calculatewight()函数?

我所尝试的:

我尝试将Clipboard.js的源代码粘贴到一个名为Clipboard.js.html的文件中,并将所有内容都放在标记中

我想要达到的目标:

单击“复制”按钮复制文本字符串


我花了几个小时寻找解决方案,但仍然找不到相关信息。如有任何帮助,将不胜感激。谢谢!

您的脚本可以有多个html文件,并且根据,您应该有html、CSS和(客户端)单独文件中的Javascript。因此,在您的示例中,index.html文件将包含所有html代码,并将添加几行代码。它可以如下所示开始:

<!DOCTYPE html>
<html>
  <head>
  <script src="//cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.4.0/clipboard.min.js"></script>
    <?!= include('myCSS'); ?>
    <title>Give it a Title</title>
  </head>
  <body>
      ...
      All the Body stuff
      ...
  </body>
    <?!= include('myScript'); ?>
</html>
我正在我的doGet中加载HTML,使用以下代码使用模板化HTML:

function doGet(passed) {

  if(passed.parameter.festival && passed.parameter.year){
    passedParameter = passed.parameter.festival + ' ' + passed.parameter.year;
  }

  var result=HtmlService.createTemplateFromFile('index').evaluate()
        .setTitle('My Title')
        .setWidth(1285)
        .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);

  return result;
}
在“文件”下拉列表下,创建一个名为myCSS的新HTML文件,并在其中添加CSS:

<style>
  h1 {
     color: #0F6B5E;
     font-size: 300%;
     text-align:center;
     vertical-align: middle;
     font-family: 'Raleway', sans-serif;
     font-weight:bold;
     padding-top: 0.5em;
     padding-bottom: 0.5em;
  }
</style>

你是一位出色的老师和问题解决者!无法表达我对你详细而清晰的解决方案的感激之情!Thxxxxx!:我无法表达这个答案的价值。谢谢!
function doGet(passed) {

  if(passed.parameter.festival && passed.parameter.year){
    passedParameter = passed.parameter.festival + ' ' + passed.parameter.year;
  }

  var result=HtmlService.createTemplateFromFile('index').evaluate()
        .setTitle('My Title')
        .setWidth(1285)
        .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);

  return result;
}
<style>
  h1 {
     color: #0F6B5E;
     font-size: 300%;
     text-align:center;
     vertical-align: middle;
     font-family: 'Raleway', sans-serif;
     font-weight:bold;
     padding-top: 0.5em;
     padding-bottom: 0.5em;
  }
</style>
<script>
  //Script to load after the page has loaded
  $(function() {
  google.script.run.withSuccessHandler(showMenuYear).withFailureHandler(loadFailed).getDropDownContent();
      });

  calculateWeight() {
    //code goes here
  }

function showMenuYear(menuItems) {
  var list = $('#optionListYear');
  var desiredValue = '<?!= passedParameter ?>';

  list.find('option').remove();  // remove existing contents

  list.append('<option value="-1">Select a Festival and Year</option>');

  for (var i = 0; i < menuItems.length ; i++) {
    list.append('<option value=' + menuItems[i].sheetrow + '>' + menuItems[i].fullFestival + '</option>');
    if (menuItems[i].fullFestival === desiredValue){
      list.val(menuItems[i].sheetrow);
    }
  }

  setFormList();

}
function setFormList() {
//    alert('In setFormList ');
//    alert($('#optionListYear').val());

  var replacement = document.getElementById("OverallGrid");
  replacement.innerHTML = "Retrieving Registrations...";

  if ($('#optionListYear').val() === "-1") {
//    if(passedData.year && passedData.festival){replacement.innerHTML = passedData.festival & " " & passedData.year;};
    replacement.innerHTML = "Select a Festival/Year above.";
    return;
  }
  google.script.run.withSuccessHandler(showRegistrationsTable).withFailureHandler(loadFailed).getValidRegistrations($('#optionListYear').val());
  }

  function loadFailed(error){
    var replacement = document.getElementById("OverallGrid");

    var displayMessage = "Error loading data: " + error.name + ' ' + error.message;

    if (error.message.includes("is missing (perhaps it was deleted?)") ) {
      displayMessage = "You do not have access to these registrations." 
    }

    replacement.innerHTML = displayMessage;

  }
</script>
google.script.run.withSuccessHandler(showMenuYear).withFailureHandler(loadFailed).getDropDownContent();