refresh a ons-page after popPage()



  • Hello,

    Is it possible to refresh the ons-page after calling popPage()?

    Use Case:

    I have page A, Page B and Page C.

    On click of button in Page A, I pushPage B.
    On click of button in Page B, I pushPage C.

    Page C has a entry form with a ons-button. On click of the button, I post to rest api to save the data into the DB and then call popPage() which puts me in Page B fine.

    Now I need to refresh Page B. Is it possible please? I use JQuery.

    Thanks for your help in advance.



  • You can use postpop event

    document.addEventListener('postpop', function(event) {
              
    var page = event.target;
    
      if (page.id === 'page1') {
           // code
        };
      else if (page.id === 'page2') {
       // code
      }
        
     });
    


  • @jamal said:

    var page = event.target;

    Thanks Jamel.

    I got that part. Then problem is refreshing the page B at postpop,

    I tried removePage() and insertPage(). Nothing seems to work.

    Any suggestion please.

    Once again thanks!



  • Jamel,

    My app has navigator with stack of pages.
    event.target page.id returns the navigator id not the current page that is getting popped.

    The above does not work.

    Thanks!



  • May be instead of event.target we can use event.enterpage.

    But the question remains how to refresh the enterpage?

    Thanks!



  • @mmike,

    BTW, it is Jamal.

    I think you ‘refresh’ a page by calling code that updates the page either thru CSS or the values of elements.

    Maybe you need to write a refresh function that updates your pages accordingly.

    As to getting correct page that popped, here is a jquery sample:

     $(document).on('postpop', '#navigator', function(event) {
              
            if (page.matches('#page3')) {
              // refresh code 
            }
          });
    

    Jamal



  • Awesome! That works great.
    Thanks for your help, Jamal!



  • Hi Jamal,

    Safari does not recognize “init” event. The above works just in chrome / firefox.

    Any thoughts?

    Thx


Log in to reply