如何使用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();"/>
对于一个很有可能在主窗口后面丢失的新窗口,并且通常会让访问者感到讨厌:
window.open('http://example.com/someImage.png');
如果我是你的话,我会坚持常规链接。
尝试:
<img src="URL or BASE64" onclick="window.open(this.src)" style="cursor: pointer;">
尝试使用以下函数:
function newTabImage() {
var image = new Image();
image.src = $('#idimage').attr('src');
var w = window.open("",'_blank');
w.document.write(image.outerHTML);
w.document.close();
}
使用此HTML代码调用:
<img id="idimage" src="data:image/jpg;base64,/9j/4A.." onclick="newTabImage()">
HTML:
<input type="button" onclick="test()" value="test">
JavaScript
function test(){
url = "https://www.google.de//images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";
img = '<img src="'+url+'">';
popup = window.open();
popup.document.write(img);
popup.print();
}
试试这个:https://jsfiddle.net/ne6f5axj/10/
你必须把图片的url放在图片标签中。
类似的东西
window.open(url,'htmlname','width=largeImage.stylewidth,height=largeImage.style.height,resizable=1');}
但是,如果有人使用AdBlock或任何PopUp Blocker,你可能会遇到麻烦。
window.Open("http://yourdomain.com/yourimage.gif");