jquery opening a csv file newline

I have some code to open a csv.

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

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


instead of what I would expect


I have tried to do

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

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

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

you have to encode the newline as html.

html = "thing,ring%0A" +
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.
Julian HansenCommented:
USe encodeURIComponent() (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)

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

Open in new window

DemosthenesAuthor Commented:
tested and confirmed.
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.

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.
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

From novice to tech pro — start learning today.