Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML img onclick Javascript

How do I have JavaScript open the current image in a new WINDOW with an ONCLICK event.

<script>  function imgWindow() {   window.open("image") } </script> 

HTML

<img src="pond1.jpg" height="150" size="150" alt="Johnson Pond" onclick="image()"> <-- Have JavaScript open this image with onclick. <img src="pond2.jpg" height="150" size="150" alt="All-green Pond" onclick="image()"> <-- Have JavaScript open this image with onclick. <img src="pond3.jpg" height="150" size="150" alt="Dutch Pond" onclick="image()"> <-- Have JavaScript open this image with onclick. 
like image 280
user3579754 Avatar asked Apr 28 '14 03:04

user3579754


People also ask

Can I use onclick on image in HTML?

The onclick is added over an image tag inside HTML. The onclick event will make our image clickable. After a user clicks on the image, you can do whatever you want, like opening a new webpage, adding animations, changing an existing image with a new one, and so on. Inside the onclick , you can pass a function.

Can you use onclick in tags?

You can call a function in 2 ways using the href or onclick attribute in the HTML tag.

How do you link an image in HTML?

To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image. With that, also add the height and width.

Can I use onclick on Div?

We can bind a JavaScript function to a div using the onclick event handler in the HTML or attaching the event handler in JavaScript. Let us refer to the following code in which we attach the event handler to a div element. The div element does not accept any click events by default.


1 Answers

here you go.

<img src="https://i.imgur.com/7KpCS0Y.jpg" onclick="window.open(this.src)"> 
like image 156
Ben Avatar answered Sep 17 '22 12:09

Ben