Search code examples
javascripttabswindow

Connect a script to an image


In the code written below, an URL opens in a resizable window. But I only want it to open when people click on an image. How do I connect this to an image? So when people click on the image, the code belows starts working.

<script>
window.open("http://www.example-url.com","mywin","menubar=1,resizable=1,width=3‌​00,height=195");
</script>

Solution

  • try this, <img onClick="openWindow()" src="PATH/TO/IMG"/>

    And in the javascript:

    function openWindow() {
    window.open("http://www.example-url.com","mywin","menubar=1,resizable=1,width=3‌​00,height=195");
    }