Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 389
Khush Avatar asked Jan 18 '12 09:01

Khush


People also ask

How do I make an image open in a new tab?

Using the keyboard shortcut Simply hold the ctrl and the alt/option key and left click on the image you would like to open in a new tab.

How do I open content in a new window?

Opening a New Window in Your Browser. Locate and click the File option in your browser menu. This is generally at the top of your browser window. Select New Window .


2 Answers

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.

like image 195
Quentin Avatar answered Oct 31 '22 16:10

Quentin


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.

like image 31
Alexander Menger Avatar answered Oct 31 '22 14:10

Alexander Menger