Welcome to WebmasterWorld Guest from 54.204.74.171

Forum Moderators: open

Message Too Old, No Replies

Escaping characters in JS

   
10:51 pm on May 7, 2003 (gmt 0)

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Can't seem to get this to work as a JS include. I'm missing the escape somewhere because it works as HTML:
* line break added to prevent side-scroll

document.writeln('<a href="#"
onClick="window.open(\'http://www.example.com/radio/player.asp?channel=pianojazz&amp;partner=23135\',\'player\',
*\'scrollbars=no,menubar=no,status=no,resize=no,toolbar=0,top=60,left=60,width=582,height=356\'); return false;" target="radio"><img src="images2/webcasts.gif" border="0" width="82" height="22" vspace="15" align="middle" alt="Jazz Webcasts"><\/a>');

[edited by: tedster at 11:16 pm (utc) on May 7, 2003]
[edit reason] prevent side scroll/use generic URL [/edit]

2:06 am on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



anyone?

2:48 am on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I haven't tried this, but you might have to also escape the double quotes.

Perhaps create a variable with the URL and just use that it in your window.open instead of trying to use the actual information and having to escape the quotes.

2:52 am on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's late and I'm not that great with JS. But I pasted your code (minus the line break stuff) into a file in my web root called /js.inc and included it in an HTML file. It didn't throw any errors in IE 6.0. That makes me wonder if there's a bug in your HTML include tag? I used <script type="text/javascript" src="/js.inc"></script>.
3:12 am on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



No, no bug in my HTML, and escaping the double quotes does not fix it either. Never had to escape double quotes before, but just for the heck of it I tried it. I have pretty much tried everything I can guess at.

4:27 am on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



keyplyr, if that code you posted was a copy/paste, look at the word writeln -- it should be writeIn, but there's a lower case "L" instead of an upper case "I"
6:17 am on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



...it should be writeIn - Tedster

What?

writeln stands for "write line", not "write in" - but thanks for trying to help, I ceratinly need it.

6:48 am on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Sucess! And it only took 12 hours.

Needed to use 2 writeln commands because the internal JS needed to all be written on one line to avoid the unterminated string constant error which was prohibiting the entire script from even displaying.

Thanks to all who helped me muddle through the possibilities.

7:35 am on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



> writeln stands for "write line", not "write in"

Wow, do I feel like an idiot. I've never used writeln, but I "thought" I knew about it. Thanks for teaching me a thing or two - I've been misreading that one for years.

9:51 am on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Good catch!

It's important to remember that document.write and document.writeln both need to be on one line. If there is a line break the script will fail.

11:33 pm on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



document.write and document.writeln both need to be on one line

Which is downright an oddity. In java, you can have the line breaks anywhere you like until the compiler sees the semi-colon. In javascript, you'd think the same syntax would carry through, but it doesn't. A CR/LF is treated like it were VB rather than a pseudo-java language.

gph

3:55 am on May 9, 2003 (gmt 0)

10+ Year Member



Just a note. You can use line breaks if the line ends in +

document.write('1' +
'<br>' +
'2')

Alerts act the same way.


alert('1' +
'\n' +
'2')