[Javascript] "unterminated string literal" error

Andy Harrison evolt at dragonzreef.com
Fri Apr 4 13:00:10 CDT 2008


Just figured it out - in the hyperlink I have to replace "%0D%0A" with
"\r\n".  I guess the string is unescaped before the javascript sees it.

On Fri, Apr 4, 2008 at 1:53 PM, Andy Harrison <evolt at dragonzreef.com> wrote:

> Thanks Peter -- I can't believe I totally missed that.  Both examples work
> now.  It still doesn't work if I put it directly in a hyperlink though
> (unless I remove the new lines):
>
> <a
> href="javascript: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');">test</a>
> BTW, I'm just experimenting - I just discovered data URLs and am seeing
> what kinds of things I can do with them.
>
> Andy
>
> On Fri, Apr 4, 2008 at 1:30 PM, Peter Brunone <peter at brunone.com> wrote:
>
> > 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
> >
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at lists.evolt.org
> > http://lists.evolt.org/mailman/listinfo/javascript
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20080404/dfa4054f/attachment-0002.htm>


More information about the Javascript mailing list