Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 765187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:50:57+00:00 2026-05-14T16:50:57+00:00

Code in the post has been modified. I was thinking that replacing \n with

  • 0

Code in the post has been modified.

I was thinking that replacing \n with
with javascript was quite a simple task, but it seems not to be so. Posts in Ask Ben or StackOverflow suggest that something as simple as:

var myRe = new RegExp(/\r?\n/g); // to avoid the re literal caching problem
lDes = $("div.descr").html(); 
lDes = lDes.replace (myRe, "<br/>"); 
lDes = lDes.replace (/(http:\/\/\S+)/g, "<a target=\"blank\" href=\"$1\">$1</a>"); 
$("div.descr").html(lDes);

will get the job done. Indeed, this work in FF and Safari but not in IE.

Or, using postie (great hint!)

Text has been created in a textarea and then stored in a database, then retrieved without further processing. It works using FF on windows and Safari on Mac. IE on windows, nada. Is it a major bug in my head? Is it a JQuery issue?

Have some idea about how to solve this? And possible reason for?

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:50:58+00:00Added an answer on May 14, 2026 at 4:50 pm

    Instead of putting the text in question into a <div> on the page, perhaps you can put it directly into a block of Javascript. Now that will require that you have some server-side code to “protect” the Javascript string constant syntax, which is a strangely rare facility but easy to create. You just have to make sure that quote characters, as well as control characters and characters outside the 7-bit range, are appropriately “escaped” the way Javascript expects string constants to look.

    Here’s what it’d look like in one of my applications. This is a Java/JSP example, so probably not what you’re using, and of course the “escape” function I call is my own invention, but just so you see what I mean:

    var theText = '${pointy:escapeJS(data.theText)}';
    $('#target').html(theText.replace(/\n/g, '<br>'));
    

    Of course if you’re receiving the text as an AJAX response, things are simpler.

    Now that example leaves out something important: you have to make sure the text is HTML-escaped before dropping it into the document. Perhaps that’s been done server-side, or if not you can do that in Javascript too:

    $('#target').html(theText
      .replace(/\r/g, '') // get rid of carriage returns
      .replace(/&/g, '&amp;')
      .replace(/</g, '&lt;')
      .replace(/>/g, '&gt;')
      .replace(/\n\n/g, '\n&nbsp;\n')
      .replace(/\n/g, '<br>')
    );
    

    (There are better/faster ways to do HTML escaping of course; that’s just an example.) Note that I stick explicit blank padding between successive newlines – that’s something I cribbed from some code I have and I think I did that because successive <br> elements without intervening “stuff” might not give multiple blank lines in the result; not sure however.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 449k
  • Answers 449k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I have answered a similar question a while ago. There… May 15, 2026 at 8:17 pm
  • Editorial Team
    Editorial Team added an answer Do you have control over your SMTP server? If so,… May 15, 2026 at 8:17 pm
  • Editorial Team
    Editorial Team added an answer .delay() only works with jQuery fx methods. .prepend() is not… May 15, 2026 at 8:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.