Open image in new window

后端 未结 7 877
执笔经年
执笔经年 2020-11-28 14:34

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

function swipe()
{   
    var largeImage = document.getElementById(\'largeImage\');
            


        
相关标签:
7条回答
  • 2020-11-28 15:04

    Try:

    <img src="URL or BASE64" onclick="window.open(this.src)">
    
    0 讨论(0)
  • 2020-11-28 15:05

    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.

    0 讨论(0)
  • 2020-11-28 15:07

    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()">
    
    0 讨论(0)
  • 2020-11-28 15:08

    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.

    0 讨论(0)
  • 2020-11-28 15:14

    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.

    0 讨论(0)
  • 2020-11-28 15:16
    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();"/>
    
    0 讨论(0)
提交回复
热议问题