/    Sign up×
Community /Pin to ProfileBookmark

newline character in innerHTML

only have test one browser – Mozilla – but have the impression, that newlines when setting innerHTML doesn’t go down very well with the browser. Is this sufficient for causing a hard crash or at least an exception? Can anyone verify that? (Just a guess now at the moment)

Thanks in advance and kind regards

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@DracoMerestAug 21.2011 — Crashing through an exception thrown by EOL character(s)? Very improbable but not impossible.

To answer you implied question, yes, different browsers have different 'newline' characters.

regExp characters are r for carriage return and n for line feed.

This is %0D and %0A respectively when using txtStr.escape("rn");

IE uses rn as does Opera.

FF and a few others use n only.

Using unescape("%0D%0A") should work in most instances.

One trick is to have a hidden TEXTAREA with a single 'newline' in it.

<textarea id="crlfChar" cols=4 rows=4>

</textarea>

Create a global variable from this:

var crlf=escape(document.getElementById("crlfChar").value);
×

Success!

Help @arvgta spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...