How can I open an image in a new window by using its id
?
function swipe()
{
var largeImage = document.getElementById(\'largeImage\');
Try:
<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()">
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.
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.
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();"/>