jquery opening a csv file newline

I have some code to open a csv.

html = "thing,ring" +
             "111,222";
window.open('data:application/text,' + html);

It works and it saves a file.  But the file has

thing,ring111,222

instead of what I would expect

thing,ring
111,222

I have tried to do

html = "thing,ring\n111,222";    and also
html = "thing,ring" + "\n" + "111,222";  and also
html = "thing,ring\
              111,222";

And the resulting file is always thing,ring111,222
        html = "thing,ring" +
               "111,222";
        window.open('data:application/text,' + html);

Open in new window

DemosthenesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mankowitzCommented:
you have to encode the newline as html.

html = "thing,ring%0A" +
             "111,222";
window.open('data:application/text,' + html);

Note that windows notepad has some trouble with non-windows line endings, but wordpad and other editors are fine with this. use %0A%0D for notepad.
0
Julian HansenCommented:
USe encodeURIComponent() (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)

Like this
html = "thing,ring\n" +
               "111,22e2";
window.open('data:application/text,' + encodeURIComponent(html));

Open in new window

0
DemosthenesAuthor Commented:
tested and confirmed.
0
Julian HansenCommented:
Something to note - the accepted answer will work if you want to manually encode all your text - the encodeURIComponent function will do that for you without having to manually insert the encoded values.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DemosthenesAuthor Commented:
Julian, I believe your answer to be the better one I am not sure how to re-open a question and give you credit for it, or if that is possible.  I tested it and it works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.