简体   繁体   中英

Calling function inside an onclick using Apps Script

I suspect there is some sanitation process in the apps script server that prevents the onclick command to pass a value to the function. Is there a work around this? Here is what I've got:

    function func() {

  var template = HtmlService.createHtmlOutputFromFile('buttons');
  var content = (template.getContent());
  Logger.log(content)
  MailApp.sendEmail({
    to: 'ggg@gmail.com',
    subject: 'subject',
    htmlBody: content

  });
}

 <!DOCTYPE html> <html> <head> <base target="_top"> </head> <body> Answer: <input type="text" id="myText" value="Try one button below"> <p>Try one of the answers below</p> <button value='ttt' onclick="f1(this)">Try it</button> <button value='ggg' onclick="f1(this)">Try it</button> <button value='hhh' onclick="f1(this)">Try it</button> <button value='eee' onclick="f1(this)">Try it</button> <script> function f1(obj){ if (obj.value == 'ttt'){ document.getElementById("myText").value = 'Correct!'; } else{ document.getElementById("myText").value = 'Wrong answer..'; } } </script> </body> </html> 

AFAIK JavaScript is not allowed on HTML content for email messages by modern email clients / services as it represent a security risk.

Related

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM