开发者

How to break line in JavaScript?

开发者 https://www.devze.com 2023-02-06 07:38 出处:网络
Please let me know how to break line in JavaScript. <input type=\'submit\' name=\'Submit\' value=\'Submit\'

Please let me know how to break line in JavaScript.

<input type='submit' name='Submit' value='Submit' 
onClick="parent.location='mailto:er.saurav123@gmail.com?subject=Thanks for writing t开发者_高级运维o me &body=I will get back to you soon. Thanks and Regards Saurav Kumar'">

I want a break line in Subject. The output I need is:

I will get back to you soon
Thanks and Regards
Saurav Kumar


Add %0D%0A to any place you want to encode a line break on the URL.

  • %0D is a carriage return character
  • %0A is a line break character

This is the new line sequence on windows machines, though not the same on linux and macs, should work in both.

If you want a linebreak in actual javascript, use the \n escape sequence.


onClick="parent.location='mailto:er.saurav123@gmail.com?subject=Thanks for writing to me &body=I will get back to you soon.%0D%0AThanks and Regards%0D%0ASaurav Kumar'


Here you are ;-)

<script type="text/javascript">
    alert("Hello there.\nI am on a second line ;-)")
</script>


I was facing the same problem. For my solution, I added br enclosed between 2 brackets < > enclosed in double quotation marks, and preceded and followed by the + sign:

+"<br>"+

Try this in your browser and see, it certainly works in my Internet Explorer.


alert("I will get back to you soon\nThanks and Regards\nSaurav Kumar");

or use %0D%0A in a url


Using + "<br>" + between each point you want to break may work for you.

e.g.

var numberTimes = 5;

for(var times = 0; times < numberTimes; times++) {
    document.write("Number of times executed: " + times + " " + "<br>");
}

document.write("It's over.")

0

精彩评论

暂无评论...
验证码 换一张
取 消