I just started with javascript and I'm trying to code an image search gallery. I'm getting the source of the images by a xml database file.
I have a for loop that goes trough the sources of the images, and then I draw each images on canvas. But what I wanna do is when I click on the images I wanna show the real sized image in another window.
How do I do that (preferably only using javascript)?
Heres the part of the code:
//goes trough the xml database searching for the image
for ( var p = 0 ; p < xmlDoc.firstChild.childNodes.length ; p ++ )
{
if ( xmlDoc.firstChild.childNodes[p].nodeName == 'path' )
{
document.getElementById("results_ID").innerHTML += xmlDoc.firstChild.childNodes[p].textContent+"<br />";
var src = xmlDoc.firstChild.childNodes[p].textContent;
//fill the array with the images
arrImg.push(src);
}
}
}
}
}
}
//resize and draw the images founded
resizeCanvas(arrImg.length);
for(var i = 0; i < arrImg.length; i++)
{
drawImg(arrImg[i]);
}
}
//function do draw the images
function drawImg(src)
{
var img = new Image();
img.onload = function ()
{
if (x > ctx.canvas.width)
{
y = y + 310;
x = 0;
}
img.width = 300;
img.height = 300;
ctx.drawImage(img, x, y, img.width, img.height); //(0,0)
x = x + 310;
};
img.src = src;
}
//function to resize the canvas by the number of images found
function resizeCanvas(nImages)
{
var height = (nImages/4);
ctx.canvas.height = Math.round(height) * 310;
alert(ctx.canvas.height);
};
Thanks in advance.