Skip to main content
Participant
May 31, 2011
Question

How to add newline character in Text in Javascript?

  • May 31, 2011
  • 2 replies
  • 4256 views

I have a Text Frame object. Call it textFrame. If I do

textFrame.contents = "Some text.";

The script changes the text as expected. But what if I want to have the text span several lines? If I do:

textFrame.contents = "Some\ntext.";

The type just shows the "\n" rather than inserting a newline. I've tried "\r" too but no dice. Is there some special way to add a newline character when assigning a value to the contents property of a TextFrame object?

Thanks!

Ben

This topic has been closed for replies.

2 replies

CarlosCanto
Community Expert
Community Expert
June 1, 2011

either, single or double quotes work on windows

textFrame.contents = "Some\rtext.";

textFrame.contents = 'Some\rtext.';

Ben9997Author
Participant
June 1, 2011

Bizarre. I'll try restarting the program and fiddling some more. No idea why the \r and \n were just showing up in the text for me. But thanks for letting me know it should work.

Cheers,

Ben

Muppet_Mark-QAl63s
Inspiring
May 31, 2011

'\r' works fine for me…