1
function showDialog(myHtmlCode) {
  var html = HtmlService.createHtmlOutputFromFile('index.html')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setWidth(800)
      .setHeight(600)
      .append(myHtmlCode); // По умолчанию дописывает код в конец index.html
  SpreadsheetApp.getUi().showModalDialog(html, '...');
}

Например как я могу вставить свой span в конкретный div имеющийся в index.html?

1 ответ 1

3
  1. In html file:
<header class="mdl-layout__header">
  <div class="mdl-layout__header-row">
    <?=myContent ?>
  </div>
</header>
  1. In gs file:
function showDialog(myHtmlCode) {

  var template = HtmlService.createTemplateFromFile('index.html')     // HTML Service: Templated HTML
  template.myContent = myHtmlCode;                                         // Put our html to the prepared place in our html file.
  var modifiedHtml = template.evaluate().getContent();                     // Get modified html raw content.

// You need to replace escape characters to the standard markup because Google automatically adds escape characters to protect against cross-site scripting (XSS) attacks
  var modifiedHtml = modifideHtml.replace(/(&lt;)/ig, "<");
  var modifiedHtml = modifideHtml.replace(/(&gt;)/ig, ">");
  var modifiedHtml = modifideHtml.replace(/(&#34;)/ig, '"');
  var modifiedHtml = modifideHtml.replace(/(&#43;)/ig, "+");

  var html = HtmlService.createHtmlOutput(modifideHtml)
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setWidth(800)
      .setHeight(600);

  SpreadsheetApp.getUi().showModalDialog(html, '...');
}
2

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.