Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

catching browser close event and showing my own popup

836858May 2 2013 — edited May 7 2013
Hi,

I want to show my own warning popup on browser close event. Kindly help me with the solution.

Thanks a lot in advance.
Lavanya.

Comments

Lavanya,

Always mention your JDev version.

Check out this thread {thread:id=2153457}

-Arun
836858
Hi Arun,

My JDEV version is 11.1.1.4.
The issue here is i am able to show warning message when user trys to close the browser. But this warning window is different for different browsers :(.
So i want to show my own warning message which will be same for all browsers. By calling popup or by calling managed bean method from the javascript.

Kindly help me on this.

Thanks in advance.

Regards,
Lavanya.
Suresh Karunarathne
Hi,
Following will useful
https://blogs.oracle.com/jdevotnharvest/entry/responding_to_the_page_unload_in_a_managed_bean
836858
Hi,

I have used this but now success.
I have written method in bean which will handle code to show faces context warning message and trying to call this method from js. but when i close browser it is simply closing the browser with out any popup.

Thanks,
Lavanya.
Lavanya,

I don't think you could show a ADF Popup during the onload event. Instead, you could use javascript's confirm method to prompt the user to choose what they want to do and perform that operation accordingly.

Ex :
jspx code
   <af:document id="d1" onunload="performUnloadEvent" clientComponent="true">
            <af:resource type="javascript">
             
              // For Mozilla and Firefox 
              if(window.addEventListener){
              window.addEventListener('beforeunload', function (event) {
                showConfirm();
              })
              }
              // For IE
              else if(window.attachEvent){
                   window.attachEvent('onbeforeunload', function (event) {
                showConfirm();
              })
              }
              
              function showConfirm(){
                      var eventSource = AdfPage.PAGE.findComponentByAbsoluteId('d1');
                      var sel = confirm("Are you sure you want to exit?");
                    if(sel==true){
                        alert('Perform OK Operation');
                        var x = AdfCustomEvent.queue(eventSource, "handleOnUnload", {result : 'ok'},false);
                        var y = 0;
                    }
                    else {
                    alert('Perform Cancel Operation');
                     var x = AdfCustomEvent.queue(eventSource, "handleOnUnload", {result : 'cancel'},false);
                     var y = 0;
                    }
              }
            </af:resource>
            <af:serverListener type="handleOnUnload" method="#{UnloadHandler.onUnloadHandler}"/>
            <af:form id="f1" clientComponent="true">
            </af:form>
        </af:document>
onUnloadHandler method in bean
    public void onUnloadHandler(ClientEvent clientEvent) {
        System.out.println("Unload Event fired..");
        String outcome = clientEvent.getParameters().get("result").toString();
        if(outcome.equalsIgnoreCase("ok")){
            System.out.println("Outcome is OK ");
            // Perform some operation like Commit;
        }
        else if(outcome.equalsIgnoreCase("cancel")){
            System.out.println("Outcome is Cancel ");
            // Perform some cleanup operation like Rollback;
        }
    }
-Arun
1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 4 2013
Added on May 2 2013
5 comments
1,325 views