Will "the Mighty" Strohl

Will Strohl's Blog


My name is Will Strohl. I'm a former employee of DNN Corp., a leader, personal branding expert, technologist, gamer, and more...

HOW TO: Escape Single Quotes for JavaScript Strings

While I was writing a class to allow me to quickly grab preformatted JavaScript functions (i.e., confirm, alert, etc.), I came across the need to ensure that a string passed into those methods would not throw a JavaScript error upon rendering. This could possibly happen if the message contained singles quotes for contractions, quotes, etc.