Jump to content
xisto Community
Sign in to follow this  
someguy

Javascript Close Window Javascript close window

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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. :P

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

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

Now replace:

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

...with...

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

and it should work. Feel free to ask if it doesn't!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I used the code given here. But somehow its not working. I duno what I missed out! Pls help me.My Code:<input type="button" value="Click To Proceed" onclick="javascript: myClose();" class="submit"> -Arthy

Share this post


Link to post
Share on other sites

javascript close window code

Javascript Close Window

 

Replying to rvalkass

 

Okay, I tried it and it didn't work. To be fair, I put your script in the last window of the sequence that began with a pop-up, but I still don't see why it shouldn't work.

 

Here's the url:

http://forums.xisto.com/no_longer_exists/

 

Click on "samples"

 

This opens a slideshow (as a pop-up). The last page (samples15.Html) includes your code

 

It doesn't close this window

 

Paul@paulpotyen.Com

 

-reply by paul Potyen

Share this post


Link to post
Share on other sites

Hi, I have a question. I don't use the button or link to close the window, but really click the close icon of the window, but I want they confirm before close the window, if not confirm the window should still open . How to implement it ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.