Welcome to WebmasterWorld Guest from 54.204.100.232

Forum Moderators: open

Message Too Old, No Replies

JavaScript Include containing JavaScript?

care with nested quotes and line breaks - the value of \escape

   
9:12 am on Mar 22, 2003 (gmt 0)

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



Wanting to include a JS pop-up window called externally. Keep getting errors. Is this not possible, or am I just screwing it up? Thanks.

document.writeln('<a href="javascript:NewWindow('/path/page.html','popup','300','260','no')"><img src="images/image.gif" border="0" width="18" height="18" alt="blah" vspace="12"><\/a>');

9:29 am on Mar 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is with the single quotes.

The single quotes in the NewWindow() call are interfering with the single quotes for the document.writeln() call.

9:32 am on Mar 22, 2003 (gmt 0)

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




Thanks - so what would be the workaround?
9:54 am on Mar 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Escaping the single quotes seem to work in IE not sure about other browsers.

document.writeln('<a href="javascript:NewWindow(\'/path/page.html\',\'popup\',\'300\',\'260\',\'no\')"><img src="images/image.gif" border="0" width="18" height="18" alt="blah" vspace="12"><\/a>');

<added>OK, also works in NN4, Moz1.3, O7</added>

10:04 am on Mar 22, 2003 (gmt 0)

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



That does work, thank you very much.

12:58 pm on Mar 22, 2003 (gmt 0)

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



Escaping the quotes should work in all browsers.

Another way is to nest double and single quotes but I see you already did this, your command needs three levels of quotes, so you have had to do all three things: single quotes, nesting double quotes, nesting escaped quotes.

6:38 pm on Mar 22, 2003 (gmt 0)

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




Hmmm, guess I'm still missing something because I can't get this to work:

document.writeln('<table width="100%" border="0" cellSpacing="0" cellPadding="0" class="foot"><tr><td width="20%" align="center"><a
href="javascript:tell_friend();">Recommend<\/a><\/td><td
width="20%" align="center"><a
href="javascript:NewWindow(\'/path/page.html\',\'popup\',\'360\',\'400\',\'no\')">Feedback <\/a><\/td><td width="20%" align="center"><a href="page.html">Link<\/a><\/td><td
width="20%" align="center"><a href="support.html">Click<\/a><\/td><td
width="20%" align="center"><a
href="javascript:NewWindow(\'/path/page.html\',\'popup\',\'400\',\'460\',\'no\')">Click<\/a><\/td><\/tr><\/table>');

Thanks

6:52 pm on Mar 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code seems to work for me. Did you put all the script on one line?, or did you break it up?
7:00 pm on Mar 22, 2003 (gmt 0)

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



I keep getting a JS error and its not displaying on the page. As far as I know, its all on one line - hmmm

<added> The error is an unterminated string constant. I know what that is... its when you break the JS line, but I don't see where I've done that? </added>

8:55 pm on Mar 22, 2003 (gmt 0)

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



Got it - I did have a broken line, but my text editor was wrapping prematurely so I didn't see it.

11:33 pm on Mar 22, 2003 (gmt 0)

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



Those can be so hard to spot. You end up having to insert a line break somewhere and see what happens to the word wrapping of all of the code after that point as you do it; but it is so easy to accidentally delete ssomething important while you are experimenting.
12:31 am on Mar 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is possible to break up JavaScript code \
onto multiple lines if you escape the carriage \
return at the end of the line!
12:52 am on Mar 23, 2003 (gmt 0)

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



That's good to know, thanks again.