Search code examples
javascriptjqueryhtmlpopupbuttonclick

how to do Button submit gets a pop a window with an image directing to other site?


I am trying a submit button to open a pop window with an image, and onclick of that image, a site should open.

Here is my code.

<button type="submit" onclick="myImg()" formenctype= "multipart/form-data" style= " width: 8em;  height: 3em; font: bold 14px sans-serif;border-radius:20px;">Send</button>

<SCRIPT>
window.onbeforeunload=confirmExit;
function myImg(){
window.name = "thiswin";
    newwin=open("http://lynx.radiocompetitions.net/wp-content/uploads/2015/04/lynx-banner.png", "dispwin", 
    "width=250,height=300,scrollbars=no, menubar=no");

       }
</SCRIPT>

The problem is, the button is not working.


Solution

  • Please have a look at following fiddle. Hope that will help you.

    http://jsfiddle.net/twsq5L43/5/

    function myImg(){
        window.name = "thiswin";
        var imagePath = "http://lynx.radiocompetitions.net/wp-content/uploads/2015/04/lynx-banner.png";
    
        newwin=open("", "dispwin", 
        "width=750,height=300,scrollbars=no, menubar=no");
    
        var otherWebsiteURL = "http://www.google.com";
    
        newwin.document.write("<div><a href='"+otherWebsiteURL+"'><img src='"+imagePath+"'></a></div>");
    
    }