homepage Welcome to WebmasterWorld Guest from 54.211.138.180
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Escaping characters in JS
keyplyr




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

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]

 

keyplyr




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

anyone?

txbakers




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

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.

GaryK




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

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>.

keyplyr




msg:1489619
 3:12 am on May 8, 2003 (gmt 0)

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.

tedster




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

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"

keyplyr




msg:1489621
 6:17 am on May 8, 2003 (gmt 0)

...it should be writeIn - Tedster

What?

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

keyplyr




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

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.

tedster




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

> 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.

BlobFisk




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

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.

txbakers




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

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




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

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')

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved