[thelist] Javascript:self.close() w/out Warning

Nik Schramm n at industriality.com
Thu Jan 30 11:03:01 CST 2003


On 30.Jan.03 16:02 Abdullah Shaikh wrote

> Javascript won't give a message on window.close() if the window was opened
> via javascript.  This is tracked via the parent property.
>
> You can fake this out, by giving the parent property a value.
>
> For example.. if you use...
>
>               window.parent = true
>
> then
>
>               self.close()
>
> will think that the window was opened by a parent window, and won't give you
> the warning.  voila.
>
> ( i am not sure of the exact syntax of the above... but that's the general
> idea )

Hi Abdullah,

actually, I find that hard to believe. O'Reilly's JS Definitive Guide,
which rarely errs on such matters, reveals that the parent property of
the window object is in fact read-only. Mozilla ignores all attempts to
overwrite this property, IE6 throws an error ("Not implemented").

Here is the code I tried:

-----------[code]-----------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> title me </title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
<!--
function shutDown() {
	window.parent = true;
	self.close();
}
//-->
</script>
</head>
<body>
<a href="javascript:shutDown()">Click</a>
</body>
</html>

-----------[/code]-----------

Do you have a functioning bit of code for this ?

--
/nik




More information about the thelist mailing list