0

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.

2 Answers 2

1

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.

1
  • Perfect, this is exactly what I wanted. I cannot used Jquery, just javascript.
    – hcarreras
    Jun 14, 2013 at 15:35
0

Rather than use a real window, could you get away with a JQuery dialog window. This is the preferred method to create popups of pure HTML.

http://jqueryui.com/dialog/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.