Khush Khush - 6 months ago 21
Javascript Question

Open image in new window

How can I open an image in a new window by using its

id
?

function swipe()
{
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.style.width=200+"px";
largeImage.style.height=200+"px";
}


This function is called on click on the image. Right now, it's opening in the same window, but I want to open it in a new window. How can this be accomplished?

Answer
function swipe() {
   var largeImage = document.getElementById('largeImage');
   largeImage.style.display = 'block';
   largeImage.style.width=200+"px";
   largeImage.style.height=200+"px";
   var url=largeImage.getAttribute('src');
   window.open(url,'Image','width=largeImage.stylewidth,height=largeImage.style.height,resizable=1');
}

HTML code:

<img src="abc.jpg" onClick="swipe();"/>
Comments