/    Sign up×
Community /Pin to ProfileBookmark

Closing browser on click on button from modaldialogbox window

Hi Experts,

I am using with JSP & java code. When i click on “Save” button in jsp, then it shows ModalDialogBox window to confirm. I get input from user & then if user clicks on “Yes”, i want to close both the modaldialogbox window & parent browser window.
But i am able to only close the ModalDialog window not parent window.
I have tried all the solutions.
please help me out.

the code which i m using is given below….

function closeWindow()
{
//alert(“hi”);
//window.opener = self;
//window.close();
//this.getTopForm(0).window.close();
//self.window.close();
//self.close();
var top = window.open(“”, “_top”);
top.close();
}

var top = window.open(“”, “_top”);
top.close();
this is working fine but giving a prompt box. I dnt want this box. I need if user click on Yes button on modaldialogbox window, everything should be closed.

Your suggestions would be appriaciated

to post a comment
JavaScript

14 Comments(s)

Copy linkTweet thisAlerts:
@felgallNov 20.2008 — You should try asking this question in a forum where people know Java - eg. try the Java forum. Perhaps ask a moderator to move the post for you rather than creating another one.
Copy linkTweet thisAlerts:
@puneetjavaauthorNov 20.2008 — I coulnot get your meaning.

This is a javascript forrum, and my question is related to this.

Where i should put my question??

Can you explain??
Copy linkTweet thisAlerts:
@voidvectorNov 20.2008 — You get a dialog box if you are trying to close user's main browser window. (i.e. the one they came to your site with) In fact on Firefox, you will get "Warning: Scripts may not close windows that were not opened by script."

Also I am not sure why you are using "top" as variable name, cause it refers to the top level window in JS.
Copy linkTweet thisAlerts:
@felgallNov 20.2008 — I coulnot get your meaning.

This is a javascript forrum, and my question is related to this.

Where i should put my question??

Can you explain??[/QUOTE]


Well at the start you refer to JSP and Java - neither of which is JavaScript. You also refer to modaldialogbox - something which JavaScript doesn't have.

Also JavaScript has no ability to close any browser windows that it didn't open from a JavaScript call from the same site.
Copy linkTweet thisAlerts:
@slaughtersNov 20.2008 — Guess what web site I hit when I googled "javascript modal dialog box" ?

Maybe he is talking about using the window showModalDialog method ie window.showModalDialog("newpage.html") ? I think this is an IE only thing. I remember using it back in the IE 5.0 days

/** EDIT - Looks like Firefox 3 now supports it as well:

https://developer.mozilla.org/en/DOM/window.showModalDialog **
/


If so, then when a value is returned from newpage.html then simply do a window.close in the parent. (most browsers *will* prompt the user warning them a script wants to close the window)
Copy linkTweet thisAlerts:
@felgallNov 21.2008 — (most browsers *will* prompt the user warning them a script wants to close the window)[/QUOTE]

No they will not. Internet Explorer is the only browser that displays a warning if a script tries to close a browser window it didn't open - so that the browser owner can cancel it to stop from losing all the other sites they have open in other tabs. All other browsers just ignore the request completely.
Copy linkTweet thisAlerts:
@slaughtersNov 21.2008 — OK - I'll rephrase that.

78% of all browsers *will* prompt the user warning them a script wants to close the window. The rest ignore it ?

puneetjava - The general rule is scripts may not close windows that were not opened by script.
Copy linkTweet thisAlerts:
@felgallNov 21.2008 — 78% of all browsers *will* prompt the user warning them a script wants to close the window. The rest ignore it ?[/QUOTE]

On your site and only if you are counting visitors rather than browsers.

If I tried it on my site only 50.5% of all visitors would display the prompt.

Only 0.1% of browsers display the prompt so the prompt will never display for those using one of the other 99.9% of possible browsers that they could be using.
Copy linkTweet thisAlerts:
@slaughtersNov 21.2008 — OK - correction.

Only 78% of *normal* people...
Copy linkTweet thisAlerts:
@felgallNov 22.2008 — OK - correction.

Only 78% of *normal* people...[/QUOTE]


Make that 78% of Americans. In most of the rest of the world IE use is much lower and falling rapidly.
Copy linkTweet thisAlerts:
@slaughtersNov 23.2008 — Make that 78% of Americans...[/QUOTE]This just a gut feel of yours, or do you know somewhere that does this kind of stats breakdown ?

I get most of this kind of info from "theCounter" ( http://www.thecounter.com/stats/2008/October/browser.php ) , but they do not do a geographic break down. I'd be interested in where you get your info.

I just wish Google would share it's "Google Analytic" data in the same sort of global trending way that theCounter does.
Copy linkTweet thisAlerts:
@puneetjavaauthorNov 25.2008 — Please guys you are going away from the actual issue. If you are having some solution, do let me know. Once more i am clearing my problem again to you guys for better understanding.

First Scenerio - when i click one button in my jsp, then my control is transfered to java class to perform some activities. From there i call one java script method to show window modaldialog box with some confirmation message. After getting response from user, again control is transfered to java to perform some tasks. Now i call finally one javascript method to close the parent window.

Second Scenerio - Secondly if i don't put java in picture means directly i write a function in javascript & call this function on click of any button in jsp then my window/browser is directly closed without any prompt.

window.opener = self

window.close()

Same lines if i put on my last javascript function as i explained in first scenerio, this does not close the window.

This is the whole scenerio. Now i think this is very clear to you.
Copy linkTweet thisAlerts:
@felgallNov 25.2008 — You didn't open the window so you can't close it. The only way you can close a window from JavaScript is to first open that window from JavaScript.
Copy linkTweet thisAlerts:
@slaughtersNov 25.2008 — ...when i click one button in my jsp, then my control is transfered to java class to perform some activities. From there i call one java script method ...[/QUOTE]I think you are confused on what is happening and how server/client interaction works on the web. JSP is a server side language (Java running on an Apache Tomcat server). When the button is clicked control has already been passed to the client and all the client has is HTML/JavaScript in a browser window.

It's *impossible* for control to be passed to a "java class to perform some activities" without a page being submitted or Ajax being used to re-query the server.

P.S.

Felgall is correct. If you don't open it, you can't close it. But, why the HECK do you want to close the parent window for anyway ? How does the parent window initially get opened ? Did you open it ?
×

Success!

Help @puneetjava spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...