Tomas Forsythe
Tomas Forsythe

Reputation: 11

Google Scripts error SyntaxError: Unexpected token < (line 119, file "Code")

I get the following ERROR

Google Scripts error

SyntaxError: Unexpected token < (line 119, file "Code")

Doesn't look to me like there are any extra chevrons.

http://prntscr.com/rvzsqd

   "{ ?> <?!= <p><span style='color:green'>Authorized Successfully</span></p> } else {?> <?!= <p><span style='color:red'>Not Authorized</span></p> }").evaluate()

Upvotes: 0

Views: 1144

Answers (1)

Steve
Steve

Reputation: 66

Try using the following for the string template. I think the problem is how you use the <?! syntax.

var template = "<b><a href='<?= getService().getAuthorizationUrl() ?>' target='_blank'>Click to Authorize</a></b><br/><? if (getService().hasAccess()) { ?> <p><span style='color:green'>Authorized Successfully</span></p> <? } else { ?> <p><span style='color:red'>Not Authorized</span></p> <? } ?>";

It's also a bit cleaner if you keep a separate HTML template file (I much prefer that, even for simple pages).

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <b>
      <a href='<?= getService().getAuthorizationUrl() ?>' target='_blank'>Click to Authorize</a>
    </b>
    <br/>
    <? if (getService().hasAccess()) { ?> 
      <p>
        <span style='color:green'>Authorized Successfully</span>
      </p>
    <? } else { ?> 
      <p>
        <span style='color:red'>Not Authorized</span>
      </p> 
    <? } ?>
  </body>
</html>

Upvotes: 2

Related Questions