...

View Full Version : Focus on pop up window not working



rcky
03-09-2012, 01:37 PM
function MyPopUpWin(message) {
var iMyWidth;
var iMyHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iMyWidth = (window.screen.width/2) - (75 + 10);
//half the screen height minus half the new window height (plus title and status bars).
iMyHeight = (window.screen.height/2) - (100 + 50);
//Open the window.
var generator = window.open();
generator.focus();
document.onmousedown = focusPopup;
document.onkeyup = focusPopup;
document.onmousemove = focusPopup;

generator.document.write('<html><head><title>Pop uP</title>');
generator.document.write('<p style="color:#C52B27;">');
generator.document.write(message);
generator.document.write('</p>');
generator.document.write('</head><body>');

generator.document.write('<a href="javascript:self.close()"><img src="/img/save_orange.gif" border=0"> <\/a>');
generator.document.write('</body></html>');
generator.document.close();
}
function focusPopup(){
if(generator && !generator.closed)
{
generator.focus();
}

}

felgall
03-09-2012, 08:24 PM
You have two separate functions there,

The first creates the popup and uses a local variable called 'generator' to load all the content into the popup.

The second function tests if a global variable called 'generator' exists and if it isn't closed in order to give that the focus. Since no such global variable exists it doesn't give anything the focus.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum