Google apps script 如何将一段html代码插入到所需位置的现有html页面中?(HtmlService.createhtmloutpfromfile))

Google apps script 如何将一段html代码插入到所需位置的现有html页面中?(HtmlService.createhtmloutpfromfile)),google-apps-script,Google Apps Script,例如,如何在index.html中的div中插入span 在html文件中: 在gs文件中: 函数显示对话框(myHtmlCode){ var template=HtmlService.createTemplateFromFile('index.html')//html服务:模板化html template.myContent=myHtmlCode;//将html放在html文件中准备好的位置。 var modifiedHtml=template.evaluate().getContent(

例如,如何在index.html中的div中插入span

  • 在html文件中:
  • 
    
  • 在gs文件中:
  • 函数显示对话框(myHtmlCode){
    var template=HtmlService.createTemplateFromFile('index.html')//html服务:模板化html
    template.myContent=myHtmlCode;//将html放在html文件中准备好的位置。
    var modifiedHtml=template.evaluate().getContent();//获取修改后的html原始内容。
    //您需要将转义字符替换为标准标记,因为Google会自动添加转义字符以防止跨站点脚本(XSS)攻击
    var modifiedHtml=modifiedHtml.replace(/()/ig,“”);
    var modifiedHtml=modifiedHtml.replace(/(";)/ig,“”);
    var modifiedHtml=modifiedHtml.replace(/(+;)/ig,“+”;
    var html=HtmlService.createHtmlOutput(modifideHtml)
    .setSandboxMode(HtmlService.SandboxMode.IFRAME)
    .setWidth(800)
    .设置高度(600);
    SpreadsheetApp.getUi().showModalDialog(html,“…”);
    }
    
    function showDialog(myHtmlCode) {
      var html = HtmlService.createHtmlOutputFromFile('index.html')
          .setSandboxMode(HtmlService.SandboxMode.IFRAME)
          .setWidth(800)
          .setHeight(600)
          .append(myHtmlCode); // By default it embeds the code to the end of the index.html
    
      SpreadsheetApp.getUi().showModalDialog(html, '...');
    }