Welcome to WebmasterWorld Guest from 54.204.107.91

Forum Moderators: open

Message Too Old, No Replies

Escaping characters in JS

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

Moderator from US 

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

joined:Sept 26, 2001
posts:7746
votes: 262


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)

Moderator from US 

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

joined:Sept 26, 2001
posts:7746
votes: 262


anyone?

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

Senior Member

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

joined:Sept 1, 2001
posts:4392
votes: 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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 17, 2002
posts:2251
votes: 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>.
3:12 am on May 8, 2003 (gmt 0)

Moderator from US 

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

joined:Sept 26, 2001
posts:7746
votes: 262


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)

Senior Member

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

joined:May 26, 2000
posts:37301
votes: 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"
6:17 am on May 8, 2003 (gmt 0)

Moderator from US 

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

joined:Sept 26, 2001
posts:7746
votes: 262


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

Moderator from US 

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

joined:Sept 26, 2001
posts:7746
votes: 262


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)

Senior Member

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

joined:May 26, 2000
posts:37301
votes: 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.

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

Senior Member

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

joined:Feb 25, 2002
posts:3185
votes: 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.

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

Senior Member

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

joined:Sept 1, 2001
posts:4392
votes: 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

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

Full Member

10+ Year Member

joined:Jan 31, 2002
posts:285
votes: 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')
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members