Luciano
Luciano

Reputation: 385

\n not working in google apps script Browser.msgBox

I am trying the following to add line breaks to a message box but it is not working.

function showMsgBox(){
  var msg = 'name: \n \n \n Doc URL';
  Browser.msgBox("Selected Doc template:", msg, Browser.Buttons.OK);
}

I does not matter single or double quotes.

I also tried Browser.msgBox(msg); but it is all the same.

What am I doing wrong?

Thank you.

Upvotes: 26

Views: 19319

Answers (2)

Corey G
Corey G

Reputation: 7858

You need to double-escape "\n" for historical reasons

function myFunction() {
  Browser.msgBox("Hello\\nWorld")
}

Upvotes: 53

Waqar Ahmad
Waqar Ahmad

Reputation: 3732

Yeah, you are right. msgBox do not respect extra whitespace or newline. A similar issue has been raised in Issue Tracker. You may star it and provide your feedback there.

Issue 1608: Add an option to Browser.msgBox() to respect whitespace

Upvotes: 0

Related Questions