5 Replies Latest reply: Oct 31, 2012 3:42 PM by kdario RSS

    Browser Back - Warning

    user8611954
      Hello,

      we have ADF application and want to implement browser back.

      When user is in page2.jspx and click Browser Back button then :

      we want to fire a javascript, that will alert user showing popup with warning (You would loose data if you go Back ! ) and then Ok button and Cancel button on it.

      If user click Ok then he would go to previous page ( page1.jspx). If user clicks Cancel button then ofcourse user will stay on same page (page2.jspx).

      Can anyone share implenmented such script that works on all Fusion browsers ?

      thanks,
      bava
        • 1. Re: Browser Back - Warning
          kdario
          You didn't mention JDev version.
          Maybe this can help: http://chrismuir.sys-con.com/node/1274700/mobile

          Dario
          • 2. Re: Browser Back - Warning
            user8611954
            thx.

            Want JavaScript approach....
            • 3. Re: Browser Back - Warning
              Frank Nimphius-Oracle
              Hi,

              the problem with allowing browser back navigation is that UI would be served from the browser cache, which then is not in synch with the server side JSF component state, which can get you into trouble. Better is perform navigation within your application if the user wants to go one step back

              Frank
              • 4. Re: Browser Back - Warning
                user8611954
                Yes. we have taken care of data sync. In case user clicks browser Back, we want to show that warning window (Ok / Cancel) and let user take decision.

                Does anyone have such javascript ?
                • 5. Re: Browser Back - Warning
                  kdario
                  To achieve this functionality, you must register listener for onbeforeunload event.
                  The problem is that you can't replace/modify default browser dialog, so maximum what you can do is to set custom message.

                  You can try something like this:
                  <f:facet name="metaContainer">            
                      <af:resource type="javascript">
                          var _checkNavigation = true;
                          
                          window.onbeforeunload = function() {
                              if(_checkNavigation){
                                  if(/Firefox[\/\s](\d+)/.test(navigator.userAgent) &amp;&amp; new Number(RegExp.$1) >= 4) {
                                      if(confirm("Are you sure?")) {
                                          history.go();
                                      } else {
                                          window.setTimeout(function() {
                                              window.stop();
                                          }, 1);
                                      }
                                  } else {
                                      return "Are you sure?";
                                  }
                              }
                          };
                          
                          function doNavigationWithoutWarning(){
                              _checkNavigation = false;
                          }
                      </af:resource>
                  </f:facet>
                  On each navigation component set clientComponent="true" and add af:clientListener:
                  <af:commandButton clientComponent="true" ....>
                        <af:clientListener method="doNavigationWithoutWarning" type="action"/>
                  </af:commandButton>
                  Dario