Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- document.write Syntax Problem in Remote Javascript


andreasfriedrich - 1:06 pm on Nov 10, 2002 (gmt 0)


My example works just fine in Netscape, Internet Explorer, Mozilla and Opera. Tedster already explained why you need those single quotes escaped.

I think I need to escape the 2 semicolons

Why would you think that. They are contained within a string and have no special meaning within a string. You only need to escape a character if it has a special meaning but you want the literal character instead of this special behavior.

" and ' are special in that they are used to delimit string literals. If you use ' as a delimiter and want to use it within the string as a literal character you need to escape it.

var x = 'Aaron\'s Party'

It would have been easier to use double quotes as the delimiter since the single quote has no specuial meaning within a double quoted string.

var x = "Aaron's Party"

Escape all the double quotes with \" and the forward slashes with \/

Why? Double quotes have no special meaning with in a string literal delimited by single quotes. Forward slashes are just ordinary characters. There is no need to escape them.

The Comment Tags: '<!--' and '// -->' are important.

Only for those very oŽld browsers that do not recognize the script element and that would therefor ignore the script tags and just display the javascript code.

See also:

String Literals [developer.netscape.com] in Client-Side JavaScript Guide.
Be careful with quotes [webbuilder.netscape.com]

Andreas


Thread source:: http://www.webmasterworld.com/javascript/224.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com