"Alias" <no@spam.org> writes:
pagecontent+='< img width="70" height="70" border="0" src="' + thumbArray[i]
+ '" onClick="loadRi ghtFrame(\"' + photoArray[i] + '\")">'
resolves to this:
pagecontent+='< img width="70" height="70" border="0"
src="pictures/unt/kl1.jpg" onClick="loadRi ghtFrame("pictu res/unt/gr1.jpg")">
Try:
pagecontent+='< img width="70" height="70" border="0" src="' + thumbArray[i]
+ '" onClick="loadRi ghtFrame(\'' + photoArray[i] + '\')">'
So it's: ', ", \', \\\", \\\\\', ...
Try:
---
var foo = 42;
var s = '"\'\\\"\\\\\'f oo\\\\\'\\\"\'" ';
alert(s);
while (typeof s == "string") {
s = eval(s);
alert(s);
}
---
I obviously cannot use double quotes OR single quotes when passing
parameters to the loadRightFrame function. Escaping the quotes is not
working either. Any ideas?
Escape single quotes.
When in doubt about something like this, I prefer to move backwards.
Start with the desired result, and then add quotes around it add
appropriate escapes.
Start with valid HTML (except the dynamic parts, which we mark so
we can remember where they are):
---
<img width="70" height="70" border="0"
src="{thumbArra y[i]}" onClick="loadRi ghtFrame('{phot oArray[i]}')">
---
Then put it in quotes of some sort. Since the string contains fewest
single quotes, that's what we'll use. That means that existing
single quotes must be escaped (if put double quotes around it, then
we would have to escape all double quotes). If there were any
backslashes, they would have to be escaped as well.
---
'<img width="70" height="70" border="0"' +
' src="{thumbArra y[i]}" onClick="loadRi ghtFrame(\'{pho toArray[i]}\')">'
---
Now the valid HTML has become a valid Javascript string. We can then
insert the dynamic parts, and the surrounding context:
---
pagecontent += '<img width="70" height="70" border="0"' +
' src="'+thumbArr ay[i]+'" onClick="loadRi ghtFrame(\''+ph otoArray[i]+'\')">'
---
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'