在新窗口中打开图像

时间:2012-01-18 09:44:18

标签: javascript image

如何使用id

在新窗口中打开图像
function swipe()
{   
    var largeImage = document.getElementById('largeImage');
    largeImage.style.display = 'block';
    largeImage.style.width=200+"px";
    largeImage.style.height=200+"px";                   
}

单击图像时调用此功能。现在,它在同一个窗口打开,但我想在新窗口中打开它。如何实现这一目标?

7 个答案:

答案 0 :(得分:20)

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();"/>

答案 1 :(得分:7)

对于一个很有可能在主窗口后面丢失的新窗口,以及一般讨厌的访问者:

window.open('http://example.com/someImage.png');

如果我是你,我会坚持常规链接。

答案 2 :(得分:3)

尝试:

<img src="URL or BASE64" onclick="window.open(this.src)">

答案 3 :(得分:0)

这样的东西
window.open(url,'htmlname','width=largeImage.stylewidth,height=largeImage.style.height,resizable=1');}

但如果有人使用AdBlock或任何PopUp-Blocker,你可能会遇到麻烦。

答案 4 :(得分:0)

尝试使用以下功能:

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()">

答案 5 :(得分:0)

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/

您必须将图像的网址放在图像标签中。

答案 6 :(得分:-3)

window.Open("http://yourdomain.com/yourimage.gif");
相关问题