如何使用id
在新窗口中打开图像?
function swipe()
{
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.style.width=200+"px";
largeImage.style.height=200+"px";
}
单击图像时调用此功能。现在,它在同一窗口中打开,但是我想在新窗口中打开它。如何做到这一点?
最佳答案
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代码:
<img src="abc.jpg" onClick="swipe();"/>