Search code examples
javascripthtmlonmouseoveronmouseout

Close a Window with onmouseout


I'm trying to do a simple page that when you put your mouse over an a popUp appears, and when you put your mouse out of the window, it closes. My code is quite simple, but doesn't work.

article class="news" onmouseover="openWindow();" >
  #some html code here
</article>

And the javascript code:

<script type="text/javascript">
    function openWindow(){
        mywin=window.open('','','width=200,height=100, left=650 top=300');
        mywin.document.write("<p>This is 'myWindow'</p>");
        mywin.document.setAttribute('onmouseout="closeWindow();"')
    }
    function closeWindow(){
         mywin.close();
    }

</script>

So openWindow() works fine, but closeWindow don't. Some idea of how can I do it?

Thanks in advance.


Solution

  • This is not a right way to hide a window but I just edit your code as per your question.

    function openWindow(){
            mywin=window.open('#','','width=200,height=100, left=650 top=300');
            mywin.document.write("<p onmouseout='window.close()'>This is 'myWindow'</p>");
    }
    function closeWindow(){
         mywin.close();
    }
    

    Instead a window open you should try any jquery plugin or other custom code.