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

JavaScript and AJAX Forum

    
JavaScript Include containing JavaScript?
care with nested quotes and line breaks - the value of \escape
keyplyr




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

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

 

msr986




msg:1482815
 9:29 am on Mar 22, 2003 (gmt 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.

keyplyr




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


Thanks - so what would be the workaround?

msr986




msg:1482817
 9:54 am on Mar 22, 2003 (gmt 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>

keyplyr




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

That does work, thank you very much.

g1smd




msg:1482819
 12:58 pm on Mar 22, 2003 (gmt 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.

keyplyr




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


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

msr986




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

Your code seems to work for me. Did you put all the script on one line?, or did you break it up?

keyplyr




msg:1482822
 7:00 pm on Mar 22, 2003 (gmt 0)

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>

keyplyr




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

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

g1smd




msg:1482824
 11:33 pm on Mar 22, 2003 (gmt 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.

msr986




msg:1482825
 12:31 am on Mar 23, 2003 (gmt 0)

It is possible to break up JavaScript code \
onto multiple lines if you escape the carriage \
return at the end of the line!

keyplyr




msg:1482826
 12:52 am on Mar 23, 2003 (gmt 0)

That's good to know, thanks again.

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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved