\n not working in google apps script Browser.msgBo

2019-04-04 00:37发布

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.

2条回答
叼着烟拽天下
2楼-- · 2019-04-04 01:08

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

function myFunction() {
  Browser.msgBox("Hello\\nWorld")
}
查看更多
Emotional °昔
3楼-- · 2019-04-04 01:15

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

查看更多
登录 后发表回答