Welcome to WebmasterWorld Guest from 54.163.34.237

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)

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:6071
votes: 75


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 7, 2001
posts:661
votes: 0


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)

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:6071
votes: 75



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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 7, 2001
posts:661
votes: 0


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)

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:6071
votes: 75


That does work, thank you very much.

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

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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)

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:6071
votes: 75



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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 7, 2001
posts:661
votes: 0


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)

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:6071
votes: 75


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)

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:6071
votes: 75


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)

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 7, 2001
posts:661
votes: 0


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)

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:6071
votes: 75


That's good to know, thanks again.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members