Monaca Onsen UI Discord Chat Github Repo

ons-back-button with refresh = true does not work

  • Onsen UI

    @mmike options.refresh was removed in v2.3.0. The correct way to refresh is what @munsterlander says, calling the function when you pop the page.

  • Thanks Fran. That’s what I did. it works fine in chome/firefox. On safari, page init is not getting triggered.

    Any thoughts on that please?

  • Onsen UI

    @mmike Check this example in Safari and see if it works. That’s a simple init event. Perhaps you are not adding the listeners soon enough in your app? Not sure. For example, event listeners should not be added inside ons.ready because that delays it.

  • Here is the code. It works perfectly fine in chrome/firefox not in safari.

      <ons-page id="rPage">
      <div class="left"><ons-back-button>Search</ons-back-button></div>
      <div id="allResults" style="text-align: left; margin-left:10px; margin-top: 30px;"></div>
        document.addEventListener('init', function(event) {
         var page =;
         if (page.matches('#rPage')) {
          $.ajax({url : "/api/get_results?src=1",
          type: "POST",
          data: "str1=N&str2=1",
          success: function(data, textStatus, jqXHR) {
          error: function(jqXHR, textStatus, errorThrown) {
                   ons.notification.alert({message: "Error ...",title: ""});

  •     });

  • Onsen UI

    @mmike Move that script to <head>...</head> and try again :+1: (or include it with <script src="..."></script>

  • Fran,

    That will not work for me because Ajax data: str1 and str2 are dynamically derived from previous page.

    The above code is generated from php. str1 and str2 parameters are available in php. If I move it to index.html, those str1 and str2 are not available.

    Any thoughts?

    Can ons-page have <head></head??

    I appreciate your help.

  • Onsen UI

    @mmike Not, it cannot have a head element. The important thing here is to register the listener before the actual event is fired. Safari might be running your code later than the other browsers so the init event has already been fired by the time the code is executed (so the listener is added too late). We don’t recommend using <script> tags inside <ons-page> to add event listeners precisely because of this unpredictable behavior of some browsers. Can’t you pass your variables in pushPage(..., { data: { /* custom data */ } }) to that page?

  • Ok Fran. How do I read the data in pushPage()?


  • That worked, Fran!


  • Hi Fran,

    Now that I send the data in in pushPage when I popPage() , this is not available.

    Sorry for asking too many questions.

    Thanks for your help!

  • Never mind…