\\n not working in google apps script Browser.msgB

2019-04-04 00:23发布

问题:

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.

回答1:

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

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


回答2:

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