"Alias" <no@spam.org> writes:
pagecontent+='<img width="70" height="70" border="0" src="' + thumbArray[i]
+ '" onClick="loadRightFrame(\"' + photoArray[i] + '\")">'
resolves to this:
pagecontent+='<img width="70" height="70" border="0"
src="pictures/unt/kl1.jpg" onClick="loadRightFrame("pictures/unt/gr1.jpg")">
Try:
pagecontent+='<img width="70" height="70" border="0" src="' + thumbArray[i]
+ '" onClick="loadRightFrame(\'' + photoArray[i] + '\')">'
So it's: ', ", \', \\\", \\\\\', ...
Try:
---
var foo = 42;
var s = '"\'\\\"\\\\\'foo\\\\\'\\\"\'"';
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="{thumbArray[i]}" onClick="loadRightFrame('{photoArray[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="{thumbArray[i]}" onClick="loadRightFrame(\'{photoArray[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="'+thumbArray[i]+'" onClick="loadRightFrame(\''+photoArray[i]+'\')">'
---
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'