Tuesday, August 5, 2008

Getting the focus back to pop-up window

In an web page on click of a button, we are getting a pop-up e-mail window. User can minimize the window and proceed with the application. We need to ensure, whenever user minimizes the window we need give an appropriate message and bring the focus back to the pop-up window.

var letterWindow;
function insufficientLimit()
{
letterWindow=window.open('insufficientLimit.do?bankKey='+cell1.childNodes[0].data+'&bankFacilityKey='+cell.childNodes[0].data,'printFriendlyView','resizable=1,width=790,height=550,status=1,scrollbars=yes');
}

function checkPopup() {
if(letterWindow != null && letterWindow.closed == false) {
alert("Please Send/Close the letter if you want to proceed");
letterWindow.focus();
}

On the parent JSP page (From where the pop-up window comes) we need to call the checkPopup() function
So when ever the user minimizes the pop-up window or clicks the parent window when the child (pop-up) window is open, the focus comes to parent window and we invoke the javascript function to get the focus back to the child (pop-up) window.
<body onfocus="checkPopup();">

One other way of doing the same is

<script type="text/javascript">
document.onmousedown=checkPopup;
</script>
</head>
<body>

Here only when the user clicks anywhere (button/text/link/etc) in the parent window we invoke the javascript function to get the focus back to the child (pop-up) window.

Related Links

Link-I

Link-II

No comments: