简体   繁体   中英

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?

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

For a new window that has a good chance of being lost behind the main window, and generally annoying visitors:

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

I'd just stick to a regular link if I were you.

尝试:

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

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();
    }

Try this: https://jsfiddle.net/ne6f5axj/10/

You have to put the url of image in an image-tag.

Try with the following function:

function newTabImage() {
    var image = new Image();
    image.src = $('#idimage').attr('src');

    var w = window.open("",'_blank');
    w.document.write(image.outerHTML);
    w.document.close(); 
}

Call with this HTML code:

<img id="idimage" src="data:image/jpg;base64,/9j/4A.." onclick="newTabImage()">

Something like

window.open(url,'htmlname','width=largeImage.stylewidth,height=largeImage.style.height,resizable=1');}

But you might run in trouble, if someone uses AdBlock or any PopUp-Blocker.

window.Open("http://yourdomain.com/yourimage.gif");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM