views:

133

answers:

1

Bascially I have a page for editing Events that needs to warn a user of unsaved changes when moving page. If the server throws an error I use Seams redirect filter to go to error.xhtml, however this pops up the confirm dialog and allows users to cancel the page redirect and remain on the broken editing page.

Can I change the below code to pull out where I'm being directed to? I've tried window.location but that still says the Event page. Is there something like a window.redirect?

<script language="JavaScript" >  
    window.onbeforeunload = confirmExit;
    function confirmExit(){
         if(isEventModified()){return "The Event has unsaved changes!";}
    }
</script>
+1  A: 

You would usually set a global flag like

warn_on_exit = true;

if the flag is true, you return your warning string, causing the confirmation message to pop up. If it's false, you return null.

Your error page would then have to emit some JavaScript that sets the flag to false.

Pekka
Hmm yes I guess I could do that, would just be a lot of boiler plate code.
stickboy144
Well, as far as I can see there is no other way...
Pekka
Actually I don't think I can do this. The redirect to the error page is done inside Seam whenever an exception is thrown and I can't change javascript variables from there.The window event is onbeforeunload, surely the redirect must be set before the page unloads? Or is this something we just dont have access to?
stickboy144
Then you would have to do it the other way round - set the "ask for confirmation" flag explicitly when your page has successfully loaded.
Pekka