...

View Full Version : How to close a window



wind0965
02-04-2004, 03:39 PM
I would like to close the window itself after I click some button or Hyperllink on it, or even press some key.
Any answer would be appreated.
Thank you!

Roy Sinclair
02-04-2004, 04:56 PM
<a href="#" onclick="window.close();">Close this Browser Window"</a>


Of course the user will get a confirmation request from the browser asking if they really want to close the window unless this window is one you opened.

SDP2006
02-04-2004, 06:01 PM
I have seen some 'close this window' that doesn't give a 'Close Window?' confirmation button. How is that done?

liorean
02-04-2004, 06:05 PM
Script generated windows (ie popups) can be closed at any time - from within, or from the generating page. There is a bug in iew that allows you to set the opener propertyr and then close the window without asking, but that is a foul hack.

glenngv
02-05-2004, 05:56 AM
Not only IE but majority of the browsers have that bug.

liorean
02-05-2004, 06:27 AM
Well, currently only saf and moz seems to disallow it. Still, one may hope. I've reported this bug to Opera as well, hoping they will correct it before 7.50 final is released.

glenngv
02-05-2004, 07:56 AM
According to the site that exploits this bug, this is the list of the browsers that either do or don't work with that hack.

wind0965
02-05-2004, 11:55 AM
Thank you for the replies.
Another question is, how to close it automaticly after a given time(e.g. 3 seconds) without doing anything.

wind0965
02-05-2004, 12:08 PM
And another possibility is to press one key to close it:
But I don't how to do it by press e.g. "Enter",
is that right to say: <a href="#" onclick="window.close();" accesskey="Chr13">.
And if I would like to press any key to close the window?

liorean
02-06-2004, 12:14 AM
Aaack! It seems Opera actually allows closing of any window, not just using this hack. This definitely goes to the OBTS.

vids
02-06-2004, 12:23 PM
If you want to close a window without the browser asking for a confirmation, use the following code:

Paste the following function into the head of your document :

function closeWinNoDialog() {
window.opener = top;
window.close();
}


Then call the function using:

<a href="javascript:closeWinNoDialog();">close window</a>

Hope this helps.....:thumbsup:

Harry
02-08-2004, 05:39 AM
Here is one I use. Seems if you give the window a name, you become the owner and then you canl close it without getting the confirm window. I use this in lots of my applications. Hope this helps.

<?php

$sript_err=str_repeat("&middot",7)." Scripting Error ".str_repeat("&middot",7);

?>
<noscript>
<html>
<head><title>Index</title></head>
<body background="blue_fade.jpg"><br><br><br><br><br><br>
<center><font size="8" face="arial" color="red">
<b><?php echo $script_err; ?></font><br><br><br>
<center><font size="6" face="arial" color="cyan">
<b>Your web browser does not have scripting enabled.<br>
Scripting must be enabled in order to run this application.<br><br>
Contact ITCS to have scripting enabled on your workstation
</font>
<bgsound src="notify.wav"></bgsound>

</body>
</html>
</noscript>

<html>
<head><title>Index</title>

<script language="javascript">
function openSite(){
var wide=screen.width;
var high=screen.height;
var where_to;

switch(wide)
{
case 640:
switch(high)
{
case 480:
where_to='ps_page_one_640.php';
}
break;
case 800:
switch(high)
{
case 600:
where_to='ps_page_one_800.php';
}
break;
case 1024:
switch(high)
{
case 768:
where_to='ps_page_one_1024.php';
}
break;
case 1152:
switch(high)
{
case 864:
where_to='ps_page_one_1152.php';
}
break;
case 1280:
switch(high)
{
case 1024:
where_to='ps_page_one_1280.php';
}
break;
default:
where_to='ps_page_one_1024.php';
}

var mainwin = window.open(where_to,"mainwin", "");
window.opener='England_swings';
window.close();
}
</script>

</head>

<body onload="openSite()">

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum