Best way to put user input into generated javascript?

Posted by Earlz on Stack Overflow See other posts from Stack Overflow or by Earlz
Published on 2010-06-13T23:45:29Z Indexed on 2010/06/13 23:52 UTC
Read the original article Hit count: 109

Filed under:
|
|
|

Hello, I need for someone to be able to put some text into a page and then this gets sent to the server, saved in the database, and else where this text is put into a javascript variable.

Basically like this:

Write("var myVar=\""+MyData+"\";");

What is the best way of escaping this data? Is there anything out there already to deal with things like ' and " and new lines? Is base64 my only option?

My serverside framework/language is ASP.Net/C#

© Stack Overflow or respective owner

Related posts about c#

Related posts about JavaScript