Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Javascript Close Window, Javascript close window
someguy
post Nov 3 2005, 07:28 AM
Post #1


Newbie [Level 2]
**

Group: Members
Posts: 31
Joined: 2-November 05
Member No.: 13,705



Hi does anyone have a code to close the browser window. This code needs to be used to close an actual full sized window, not a pop-up window.
Go to the top of the page
 
+Quote Post
electriic ink
post Nov 3 2005, 07:31 AM
Post #2


Incest is a game the whole family can play.
Group Icon

Group: [MODERATOR]
Posts: 1,227
Joined: 11-February 05
From: Heaven
Member No.: 3,709



Try this:

CODE
<a href="javascript:window.close()">Close this window!</a>


I think it's the same regardless of what size the window is.

Go to the top of the page
 
+Quote Post
Spectre
post Nov 3 2005, 10:00 AM
Post #3


Privileged Member
*********

Group: Members
Posts: 874
Joined: 30-July 04
Member No.: 246



In some browsers, closing a top-level window via JavaScript's window.close() will result in a confirmation dialog being displayed. That I know of, this cannot be prevented through the code itself (you may be able to disable it in some browsers, though). Only new windows opened from within that window may be closed without confirmation. Other browsers, however, will simply close the window, no questions asked; it just depends on the respective JavaScript engine and how the developers have opted to handle such an event by default.
Go to the top of the page
 
+Quote Post
leiaah
post Nov 3 2005, 02:47 PM
Post #4


Super Member
*********

Group: Members
Posts: 436
Joined: 21-January 05
From: Koronadal City, Philippines
Member No.: 3,358



I agree with Spectre. Browsers like Internet Explorer will display a pompt first before closing the window. You should consider those who visit your site and what browser they're using. smile.gif
Go to the top of the page
 
+Quote Post
cse-icons
post Nov 3 2005, 02:56 PM
Post #5


Super Member
*********

Group: Members
Posts: 351
Joined: 19-October 04
From: India
Member No.: 1,824



hi,

yeah, Internet Explorer always prompts for confirmation before closing the main window. I m not sure of other browser but I suppose most would.

But I visited a certain site where on logging out, the particular window closed and opened a new browser window with a link 'Close this window'. On clicking the link the window closed without any confirmation dialog box. In effect this closed the main window without any dialog box. I m not sure how it was done.. I do not have the site bookmarked too so that I can check it out again..

Did nyone else come across this sort of situation? If nyone knows the solution please post it here.

Cheers.
Go to the top of the page
 
+Quote Post
rvalkass
post Nov 3 2005, 07:34 PM
Post #6


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,156
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



There is a way to get around the confirmation problem, simply by instructing the browser that the window was actually opened with javascript, regardless of whether the window was or not.

CODE

function NoConfirm ()
{
win = top;
win.opener = top;
win.close ();
}


Now replace:

CODE

<a href="javascript:window.close()">Close this window!</a>


...with...

CODE

<a href="javascript:NoConfirm()">Close this window!</a>


and it should work. Feel free to ask if it doesn't!
Go to the top of the page
 
+Quote Post
Spectre
post Nov 3 2005, 10:32 PM
Post #7


Privileged Member
*********

Group: Members
Posts: 874
Joined: 30-July 04
Member No.: 246



Ah, very good, rvalkass. It does indeed work. I didn't know it was possible with Internet Explorer at all. And that is why client-side scripting languages are not my area.
Go to the top of the page
 
+Quote Post
iGuest
post Oct 2 2007, 08:25 PM
Post #8


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



<a href="javascript:window.opener='x';window.close();">Close me</a>
Go to the top of the page
 
+Quote Post
iGuest
post Oct 23 2007, 05:03 AM
Post #9


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



Thank you for your suggestion.

-CHMOKARAT
Go to the top of the page
 
+Quote Post