[Javascript] "unterminated string literal" error
Andy Harrison
evolt at dragonzreef.com
Fri Apr 4 12:18:52 CDT 2008
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/856b5473/attachment-0001.htm>
More information about the Javascript
mailing list