how to Trigger click on back button by clicking on another button?



  • Hi,

    I’m trying to trigger the back button by clicking on another button.

    I’m simplly using jQuery click function to do this.

    issue that i have is that my code only works in browsers but when I create a phonegap APP, the code doesn’t work at all!

    This is my code:

    document.addEventListener("show", function(event){
     
     
    if(event.target.id=='page2') {
    
    
     $(".bak").on('click', function(){
     
    /*$( ".back-button" ).trigger( "click" );*/
    
    $('#backing').click();
     
    }); 
    
       }
       
    });
    

    and this is my Back button:

    <ons-back-button id="backing">Back</ons-back-button>
    

    and finally this is my button that I click on to trigger the back button:

    <img class="bak" width="70%" src="back-btn.png" style="float:left;">
    
    
    Could someone please advise on this issue?
    
    
    Thanks in advance.
    


  • @Jackson All the back button is doing is issuing the poppage command for your navigator. You can simply call:

    myNavigator.popPage();
    

    And get the same effect.

    More info can be found in the docs here:

    https://onsen.io/v2/docs/js/navigation.html

    If you need more control, then referencing the docs here:

    https://onsen.io/v2/docs/js/ons-back-button.html

    Shows that you can specify your own function for the button to call that you can also have your other button call.



  • @munsterlander you are a god send mate… I love you and I love onsen ui… :)



  • @Jackson Thank you! Here to help!


Log in to reply