Discussion:
warn on exit from browser
rebecca
2011-05-12 06:04:55 UTC
Permalink
Hello all,

I would like to know if there is a way to open a popup window just before
the user tries to exit the browser window?

I tried using the "onbeforeunload" event on the body tag and managed to get
a prompt message that enables me to go back to the page i tried to exit.

Do you know a better solution?

Thanks
Rebecca

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/warn-on-exit-from-browser-tp3516569p3516569.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Andrea Del Bene
2011-05-12 09:00:12 UTC
Permalink
I think JavaScript is the only way to do what you want. You can find
something useful on stackoverflow:

http://stackoverflow.com/questions/1631959/browser-window-close-event#1632004
Post by rebecca
Hello all,
I would like to know if there is a way to open a popup window just before
the user tries to exit the browser window?
I tried using the "onbeforeunload" event on the body tag and managed to get
a prompt message that enables me to go back to the page i tried to exit.
Do you know a better solution?
Thanks
Rebecca
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/warn-on-exit-from-browser-tp3516569p3516569.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
rebecca
2011-05-12 09:16:10 UTC
Permalink
Thank you andrea, but i already managed to use javascript to show a confirm
dialog.

What I would like to know is if it is possible to change the default
behavior of the browser and to show a wicket popup instead of the confirm
dialog?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/warn-on-exit-from-browser-tp3516569p3516849.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Andrea Del Bene
2011-05-12 10:04:01 UTC
Permalink
So far as i know Wicket can't help you that much since this is a "pure"
client side problem.
Post by rebecca
Thank you andrea, but i already managed to use javascript to show a confirm
dialog.
What I would like to know is if it is possible to change the default
behavior of the browser and to show a wicket popup instead of the confirm
dialog?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/warn-on-exit-from-browser-tp3516569p3516849.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Hielke Hoeve
2011-05-13 06:51:37 UTC
Permalink
You could use an ajax callback to wicket in the onbeforeunload and do
something serverside but showing a modalwindow is probably impossible as
the onbeforeunload will continue after the ajax call is done...

Hielke

-----Original Message-----
From: Andrea Del Bene [mailto:***@ciseonweb.it]
Sent: donderdag 12 mei 2011 12:04
To: ***@wicket.apache.org
Subject: Re: warn on exit from browser

So far as i know Wicket can't help you that much since this is a "pure"

client side problem.
Post by rebecca
Thank you andrea, but i already managed to use javascript to show a
confirm dialog.
What I would like to know is if it is possible to change the default
behavior of the browser and to show a wicket popup instead of the
confirm dialog?
--
http://apache-wicket.1842946.n4.nabble.com/warn-on-exit-from-browser-t
p3516569p3516849.html Sent from the Users forum mailing list archive
at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Martin Grigorov
2011-05-13 07:04:20 UTC
Permalink
I'm not sure this will work.
First the Ajax call should be synchronous otherwise onbeforeunload will
continue and unload the DOM/page. Second the returned ajax response is
executed again in asynchronous way - using function chaining, and I think
this will also "release the lock".
Canceling the onbeforeunload event earlier (event.returnValue = false) and
then using normal asych Ajax to show the modal will do it halfway - there is
no way to continue to the original destination after the user say "Yes,
close"
Post by Hielke Hoeve
You could use an ajax callback to wicket in the onbeforeunload and do
something serverside but showing a modalwindow is probably impossible as
the onbeforeunload will continue after the ajax call is done...
Hielke
-----Original Message-----
Sent: donderdag 12 mei 2011 12:04
Subject: Re: warn on exit from browser
So far as i know Wicket can't help you that much since this is a "pure"
client side problem.
Post by rebecca
Thank you andrea, but i already managed to use javascript to show a
confirm dialog.
What I would like to know is if it is possible to change the default
behavior of the browser and to show a wicket popup instead of the
confirm dialog?
--
http://apache-wicket.1842946.n4.nabble.com/warn-on-exit-from-browser-t
p3516569p3516849.html Sent from the Users forum mailing list archive
at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>
rebecca
2011-05-19 06:53:11 UTC
Permalink
Thank you all for replying

It does sound like I'm trying to do something impossible, but I would like
to post my code here in case i did not explain the problem correctly:

I add onbeforeunload event to the body of my page, which calls a JS
function. The JS does submit to my form. In my form onSubmit() I do a
setResponsePage.

I see that it get's into the onSubmit() (and even to the destination page's
constructor), but after exit from onSubmit(), it returns to the original
page (refereshing the entered data).

Here's the code:

on page
--------
body.add(new SimpleAttributeModifier("onload", "isSubmit=false;"));
StringBuilder js = new StringBuilder();
js.append("if(!isSubmit){checkLeaving( '");
js.append(getString("leaveWizardMessage"));
js.append("', '");
js.append(newAccountWizard.getForm().getMarkupId());
js.append("', '");
js.append(newAccountWizard.getConfirmationModal().getMarkupId());
js.append("')};");

body.add(new SimpleAttributeModifier("onbeforeunload", js.toString()));
add(body);

js file
--------
function checkLeaving(message, formId, modalId, linkId){

//alert("formId = " + formId);
var answer = confirm(message);
if(answer == true){
var form = document.getElementById(formId);
//var modal = document.getElementById(modalId);
//var submitLink = document.getElementById(linkId);
alert("before submit");
form.submit();
//submitLink.onclick();
//return false;
}
}

wizard panel
-------------
@Override
protected Form newForm(String id) {

form = new Form(id){

@Override
protected void onSubmit() {
System.out.println("in form submit1");
setResponsePage(NewAccountRegistrationPage.class);
System.out.println("in form submit2");
}

protected void onError() {
System.out.println("in form error");
};
};



Can someone please tell me if it's possible?

Rebbaca


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/warn-on-exit-from-browser-tp3516569p3534945.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Robert Dahlström
2011-05-19 07:06:01 UTC
Permalink
With just a quick look:
setRedirect(true)

may help and not just setResponsePage()

Regards
Robert
Post by rebecca
Thank you all for replying
It does sound like I'm trying to do something impossible, but I would like
I add onbeforeunload event to the body of my page, which calls a JS
function. The JS does submit to my form. In my form onSubmit() I do a
setResponsePage.
I see that it get's into the onSubmit() (and even to the destination page's
constructor), but after exit from onSubmit(), it returns to the original
page (refereshing the entered data).
on page
--------
body.add(new SimpleAttributeModifier("onload", "isSubmit=false;"));
StringBuilder js = new StringBuilder();
js.append("if(!isSubmit){checkLeaving( '");
js.append(getString("leaveWizardMessage"));
js.append("', '");
js.append(newAccountWizard.getForm().getMarkupId());
js.append("', '");
js.append(newAccountWizard.getConfirmationModal().getMarkupId());
js.append("')};");
body.add(new SimpleAttributeModifier("onbeforeunload", js.toString()));
add(body);
js file
--------
function checkLeaving(message, formId, modalId, linkId){
//alert("formId = " + formId);
var answer = confirm(message);
if(answer == true){
var form = document.getElementById(formId);
//var modal = document.getElementById(modalId);
//var submitLink = document.getElementById(linkId);
alert("before submit");
form.submit();
//submitLink.onclick();
//return false;
}
}
wizard panel
-------------
@Override
protected Form newForm(String id) {
form = new Form(id){
@Override
protected void onSubmit() {
System.out.println("in form submit1");
setResponsePage(NewAccountRegistrationPage.class);
System.out.println("in form submit2");
}
protected void onError() {
System.out.println("in form error");
};
};
Can someone please tell me if it's possible?
Rebbaca
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/warn-on-exit-from-browser-tp3516569p3534945.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
rebecca
2011-05-23 09:24:15 UTC
Permalink
Thanks Robert, but the setRedirect(true) did not help me

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/warn-on-exit-from-browser-tp3516569p3543593.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org

Continue reading on narkive:
Loading...