Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click on Image display image on new window

Tags:

html

css

I get data from the database in which is images and some other fields, now I want that when I click on the Image they open in the new window my code is

<a target="_blank" href="#">
                  <img alt="" src="<%#"data:Image/png;base64,"+Convert.ToBase64String((byte[])Eval("ImageData"))  %>"" width="200" height="200" />

             </a>

what should I do this img pass to next window and display large or actual size

like image 937
Ali Imran Avatar asked Jul 25 '17 13:07

Ali Imran


2 Answers

You need to add some javascript to your code.

// HTML

 <a target="_blank" href="#" onClick='test(this)'>
 <img alt="" src="<%#"data:Image/png;base64,"+ Convert.ToBase64String((byte[])Eval("ImageData"))  %>"" />
 </a>

// Javascript Code

 function test(element) {
        var newTab = window.open();
        setTimeout(function() {
            newTab.document.body.innerHTML = element.innerHTML;
        }, 500);
        return false;
    }

Demo Fiddle

like image 165
Arif H-Shigri Avatar answered Sep 30 '22 06:09

Arif H-Shigri


The href attribute of the a tag has to contain the same filepath as the src attribute inside the img tag. You already added target="_blank", so the image will open in a new window, in original size, showing nothing else than the image.

like image 36
Johannes Avatar answered Sep 30 '22 06:09

Johannes