Common sources of unterminated string literal [duplicate] Common sources of unterminated string literal [duplicate] javascript javascript

Common sources of unterminated string literal [duplicate]


Most browsers seem to have problems with code like this:

var foo = "</script>";

In Firefox, Opera and IE8 this results in an unterminated string literal error. Can be pretty nasty when serializing html code which includes scripts.


Look for linebreaks! Those are often the cause.


I would vote for jamtoday's answer if I had the "reputation"

If your data is coming by way of PHP, this might help

$str = str_replace(array("\r", "\n"), '', $str);