Open picture in new window

How to open an image in a new window using 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 when you click on the image. Right now, it opens in the same window, but I want to open it in a new window. How can I do that?

+6
source share
5 answers
 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();"/> 
+17
source

For a new window, which has good chances to get lost behind the main window and, as a rule, annoys visitors:

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

I would just stick with a regular link if I were you.

+7
source

Try:

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

Sort of

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

But you may have problems if someone uses AdBlock or any PopUp-Blocker.

0
source
 window.Open("http://yourdomain.com/yourimage.gif"); 
-3
source

Source: https://habr.com/ru/post/906286/


All Articles