[Javascript] "unterminated string literal" error

Peter Brunone peter at brunone.com
Fri Apr 4 12:30:45 CDT 2008


Is this some proof-of-concept tour of what Javascript can do with hex encoding?

I don't think you can continue a string on the next line.  You've closed the string and added the concatenation operator in the first example, but in the second, you've left the greater string wide open.

Cheers,

Peter

----------------------------------------

From: "Andy Harrison" <evolt at dragonzreef.com>

As an experiment, I'm trying to open a new window using a data URL.  In one scenario I get an error and I don't understand why.

This works fine:

        window.open('data:text/html,%3Chtml%3E%0D%0A'+
        '%3Chead%3E%3Ctitle%3Etest%3C%2Ftitle%3E%3C%2Fhead%3E%0D%0A'+
        '%3Cbody%3E%3Ch1%3E42%3C%2Fh1%3E%3C%2Fbody%3E%0D%0A'+
        '%3C%2Fhtml%3E');

But if I put it in a string (e.g., the href attribute of a hyperlink, preceded by "javascript:"), I get an "unterminated string literal" error:

        eval("window.open('data:text/html,%3Chtml%3E%0D%0A'+
        '%3Chead%3E%3Ctitle%3Etest%3C%2Ftitle%3E%3C%2Fhead%3E%0D%0A'+
        '%3Cbody%3E%3Ch1%3E42%3C%2Fh1%3E%3C%2Fbody%3E%0D%0A'+
        '%3C%2Fhtml%3E');");

I know it has something to do with %0D%0A (carriage-return, line-feed), because both work fine if I remove them--but then the new lines don't show up in the source code of the new window.  Not important, I know, but I'm curious.  Any ideas why this is happening?

Andy


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20080404/544d7e36/attachment.htm>


More information about the Javascript mailing list