Vinod Kumar
Vinod Kumar

Reputation: 771

Pop up window getting closed even when mouse pointer is at the top of the popup window

I want to implement popup functionality for a page, for which I used the below code.

 <input type="button" value="Open a Popup Window" onclick="window.open('WebForm2.aspx','popUpWindow','height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');">


using this I was able to open a new window. but also I have to close the popup window if the user moves the cursor (i.e onmouseout) from the popup window and also I want to close the popup when user clicks the X button on the right corner of the tab. For that what I did was

    <script type="text/javascript">    
        function alertUser() {
            window.close();
        }
    </script>

<div onmouseout ="alertUser()"> My contents ... </div>. 


Now my problem is when the cursor is moved near the close btn without clicking the window is closed. What can be done?

Upvotes: 0

Views: 1086

Answers (1)

Brian Warshaw
Brian Warshaw

Reputation: 22984

The problem is that your onmouseout listener is on the div. When the mouse leaves the div, window.close() is triggered. There isn't any way to listen for events on application chrome (like the title bar of the window), so there's not much you can do. You can style the div so that it takes up the entire content area of the window, but that's about it. You can also consider changing your design so that leaving the window/div doesn't cause it to close. That could be startling behavior for a user, anyhow.

Upvotes: 1

Related Questions