PDA

View Full Version : Closing window without confirmation prompt



codeexploiter
01-31-2007, 06:05 AM
Hi

I need a method to close the main browser window using
window.close() without getting a confirmation prompt.

Is this possible or is there any other way to achieve the same result?

Any help will be highly appreciated.

Regards

beeps
01-31-2007, 06:28 AM
Please have a look to the attachment(open.html).Its just a work around as I think its not possible to close the brow760eser window without an alert msg.

codeexploiter
01-31-2007, 06:42 AM
The files you attached in your posting doesn't working as I want. Let me clear my points.

1. I have only one window which is not generated using script. (There is no scope for a popup window in my case).

2. I need to close my only window (main window) using JavaScript code in such a way that it doesn't show the browser closing confirmation box.

beeps
01-31-2007, 08:49 AM
Fine ...I got your point.
Please try this attachment. I tested it in i.e.6.0. Its working fine 761.
code:
<script language="JavaScript">
function fCloseOpener(){
window.opener = self
window.close()
}
</script>

codeexploiter
01-31-2007, 11:01 AM
Fine ...I got your point.
Please try this attachment. I tested it in i.e.6.0. Its working fine 761.
code:
<script language="JavaScript">
function fCloseOpener(){
window.opener = self
window.close()
}
</script>

In IE 7 the above code doesn't work correctly.

I've tested it with IE 6 and the window seems to be stucked it did not close for me.

djr33
01-31-2007, 11:17 AM
John came up with a code that does this. It convinces JS that the window WAS opened by it then allows it to close the window. Search around for it... not sure where it is at the moment.

Edit: here we go...


<script type="text/javascript">
if(window.name!='prime'){
window.name='prime';
window.open(window.location.href, 'prime')
}
</script>

He said, in short, that once this is on the page, it allows window.close() etc. to work properly.

jscheuer1
01-31-2007, 05:12 PM
I found that, for some reason, IE versions 6 and below didn't like that but, they always had responded well to another hack that other browsers ignored so, in the end I went with this:


<script type="text/javascript">
if(window.name!='prime'){
window.name='prime';
window.open(window.location.href, 'prime')
}
</script>
<!--[if lte IE 6]>
<script type="text/javascript">
window.opener=self;
</script>
<![endif]-->

What it does is to reopen the window in the same window using javascript based upon whether or not it has the name 'prime'. Then (except in IE 6 and below) it can be closed using javascript. In IE 6 and less it also tells the browser, "Hey - I am the opener so, you can close me with javascript."

This has the side effect of assigning the window the name of 'prime' (or changing its name to that if it had one). This could cause problems if you have any other code that relies upon the window's name being something else or null. But, this should be able to be worked around if it is at issue in your setup.

Mohit2611
11-10-2010, 11:30 AM
@ djr33

Thanks for explaining.

Thank you everyone. :)