View Full Version : document.write('\/')

03-16-2004, 10:39 PM
Hi. Here's the situation. I have a asp script. It does:

x = '<a href="http:\/\/tmp.htm">title<\/a>'
Response.Write("a[0] = '"+x+"'")

which generates this javascript code:

a[0] = '<a href="http://tmp.htm">title</a>'

At some point the javascript code will do a document.all('id').innerHTML = a[0].

This works, but I'm confused. Isn't innerHTML just like write(), in that all '/' needs to be set to '\/'. Just when do you have to do this kind of parsing?

03-16-2004, 11:20 PM
when the / could mean something else.

I use when I use a lot of quotes.

say I want to alert "hello" (with the quotes) but it is onclick.

onclick=" /"hello/" "

03-17-2004, 01:37 AM
Shouldn't that be the backslashes instead of forward slashes, shlagish?

A backslash is used to escape special characters, such as quotes, forward slashes etc.

03-17-2004, 02:17 AM

yes yes, listen to Nightfire, he's got me outwised :D

03-17-2004, 03:04 AM
I just want to find out when you need to convert '/' to '\/'...Dennis

03-17-2004, 03:30 AM
when you are writing out strings that have closing tags especially the </script> tag.

document.write('<script src="file.js"><\/script>');