Problem with onBlur="window.close()" and MS IE 6

P

Peter Pagé

Hi,

I've got a window with a "<body onBlur="window.close()"> tag that keeps
closing prematurely. It happens when the user clicks on text inside a table
in the same window. Apparently IE decides that the <body> no longer has the
focus if the <table> within the <body> has it. Firefox handles the page
correctly as does MS 5.

This may be one of those "security features" that came along with Windows XP
SP2, but wherever it came from, it's a real pain in the you-know-what. Does
anyone know of a work-around for this?

Thanks,
Peter
 
K

kaeli

This may be one of those "security features" that came along with Windows XP
SP2, but wherever it came from, it's a real pain in the you-know-what. Does
anyone know of a work-around for this?

A guess:

Use the standards compliant doctype?
Seems like it matters...

http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/body.asp
As of Internet Explorer 6, when you use the !DOCTYPE declaration to specify
standards-compliant mode, the body object can obtain its size from its
content, or you can set its size explicitly=3Flike a div object, for example.
In standards-compliant mode, the html element represents the entire surface
onto which a document's contents can be rendered. When the !DOCTYPE
declaration does not specify standards-compliant mode, and with earler
versions of Internet Explorer, the body object represents the entire surface
onto which a document's contents can be rendered. The size of the body object
cannot be changed and is equal to the size of the window. Margins you set on
this object are rendered inside the border and scrollbars of the object.

--
 
R

RobB

Peter said:
Hi,
I have a window with a <body onBlur="window.close()"> tag that is closing
prematurely. The problem occurs when the user clicks on text in the window
that is within a table. Apparently IE decides that if the <table> has
focus, then the <body> doesn't, and so it should close the window. This
may be one of those new Win XP SP2 "security features" since Firefox
handles the code correctly and so does a MS IE v.5 (Mac version).

Has anyone found a workaround for this new 'feature'?

Thanks,
Peter

Can't say I've dealt with that particular 'feature' - but there's a
reasonable workaround for the need to set focus on text inputs in such
a window without closing it. Use a timer:

var blurtimer = null;
var closeOK = true;

self.onblur = function()
{
blurtimer = setTimeout('if(closeOK)self.close()', 100);
}

You then have the delay period to block the closer script from any
onfocus handler:

<table onfocus="closeOK=false;" onblur="closeOK=true;">

[untested]
 
P

Peter Pagé

Thanks for the suggestion.; it sounded like the solution, but apparently it
isn't. Any other suggestions would be more than welcome at this point -
I've spent the whole day on alternatives and nothing seems to work.

A simplified version of the code for the page, which is generated by PHP
when a user submits a form, looks like this.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
</head>

<body onblur="Javascript:window.close()" >

<table>
<tr>
<td>
<p>SAVAGE, Anne</p>
<p>Born: Montreal Quebec, 1896</p>
<p>Died: Montreal Quebec, 1971</p>
</td>
</tr>
</table>

</body>
</html>
I get the same results whether I use the DOCTYPE tag or not. I've even
tried each of the following declarations, all with the same results; the
window closes if I click on the displayed text.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
" http://www.w3.org/TR/html4/loose.dtd">
Peter

P.S. Not that it changes the behaviour of the page, but in the application
I'm writing, the name "SAVAGE, Anne" is actually a link that will bring up a
more complete record about that person. This has no direct bearing on the
problem, but does restrict the range of possible solutions.

-----------------------------
 
P

Peter Pagé

Woo-hoo! I had to modify it a lot to get it to work with my particular
problem, but using a timer was the key.

Thank you very much!
Peter



RobB said:
Peter said:
Hi,
I have a window with a <body onBlur="window.close()"> tag that is closing
prematurely. The problem occurs when the user clicks on text in the window
that is within a table. Apparently IE decides that if the <table> has
focus, then the <body> doesn't, and so it should close the window. This
may be one of those new Win XP SP2 "security features" since Firefox
handles the code correctly and so does a MS IE v.5 (Mac version).

Has anyone found a workaround for this new 'feature'?

Thanks,
Peter

Can't say I've dealt with that particular 'feature' - but there's a
reasonable workaround for the need to set focus on text inputs in such
a window without closing it. Use a timer:

var blurtimer = null;
var closeOK = true;

self.onblur = function()
{
blurtimer = setTimeout('if(closeOK)self.close()', 100);
}

You then have the delay period to block the closer script from any
onfocus handler:

<table onfocus="closeOK=false;" onblur="closeOK=true;">

[untested]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top