-1

I want to have my browser tab title for Gmail show the Subject for the current email because I have software that helps time tracking by capturing tab titles. Unfortunately, it shows Inbox (6) - my.name@mycompany.com all the time.

I see Change Title With Javascript provides javascript to change the tab title to alternative text. How would I get the Subject of the current message in Gmail in a Gmail add-on?

Joe Murray
  • 545
  • 4
  • 19

1 Answers1

0

assuming you are retrieving a message of type GmailMessage and that you are running your js client side in an HTML context such as a webapp you could:

  • create a function in app script that calls the method getSubject()
  • Serve HTML
  • call backend function with google.script.run
  • call a success handler that changes title when async function is completed with success.

in your HTML

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
      function onSuccess(subject) {
        document.title = subject
      }
      google.script.run.withSuccessHandler(onSuccess)
          .getSubject();
    </script>
  </head>
  <body>
    <div id="output"></div>
  </body>
</html>

and in your .gs

getSubject(){
 //get your message here
 return (message.getSubject());
}

REFERENCES

JSmith
  • 3,635
  • 3
  • 24
  • 36