bosoxbill Posted March 26, 2013 Share Posted March 26, 2013 How can I get Javascript to see a block of text as literal text without having to escape characters? I need to load a block of text and do multiple searches and replacements, but I'm going to get errors if the block of text has characters that need to be escaped that I don't know about. Is this possible and if not, what programming language should I use? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 26, 2013 Share Posted March 26, 2013 If you're talking about printing a string of text as a Javascript variable then you need to escape quotes, newlines, and slashes. Otherwise, you can load it from an external source like a text file or database. It's easy enough to add slashes before characters that need them, but it's hard to suggest a solution without knowing exactly what you're trying to do. Link to comment Share on other sites More sharing options...
bosoxbill Posted March 26, 2013 Author Share Posted March 26, 2013 You answered my question. Just a follow up: Would I use another script such as Perl to add those slashes before the external text file was loaded? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 27, 2013 Share Posted March 27, 2013 You can use Javascript to load the text file via ajax as long as it is on the same domain. You don't need to escape anything if you're saving the response from the ajax call in a Javascript variable (it will already be in a variable, actually). Link to comment Share on other sites More sharing options...
bosoxbill Posted March 27, 2013 Author Share Posted March 27, 2013 Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now