JavaScript “back” button goes to destination then back to original page

I am using Phonegap and jQuery to develop an app.

I have a bit of a bug that has me stumped.

I have a back button which looks like this:

<div data-role="header">
        <a id="backFromModules" data-role="button" data-icon="back">Back</a>
        <h1 id="mHeader" class="wrap"></h1>
    </div>

and the javascript to make the button navigate back to the #home page:

$(document).on("click", "#backFromModules", function(event){
    console.log("back from modules");
    $.mobile.changePage("#home");

});

when I click on the back button it navigates to "#home" and then back to the modules page, but this only occurs intermittently, and randomly.

this video should better explain it: https://youtu.be/CyQz0KiNC64

I have no idea how I could debug this, or what could be causing the bug. If anyone has any thoughts, please let me know

EDIT

the full code of this page can be found here:

<div id="modules" data-role="page">
    <div data-role="header">
        <a id="backFromModules" data-role="button" data-icon="back">Back</a>
        <h1 id="mHeader" class="wrap"></h1>
    </div>
    <div data-role="content">
        <p>Below is a list of e-learning modules which can be viewed for this course</p>
        <ul id="mList" data-role="listview" data-inset="true">
            <li>An error has occurred!</li>
        </ul>
    </div>
    <div data-role="footer" data-position="fixed" class="ui-grid-b">
        <div class="ui-block-a">
            <p>&copyCopyright information</p>
        </div>
        <div class="ui-block-b">
        </div>
        <div class="ui-block-c">
            <div class="ui-btn-right" data-role="controlgroup" data-type="horizontal">
                <a target='_blank' href="#about" data-transition="slideup"  data-role="button" data-iconpos="notext" data-icon="info"  >About</a>
            </div>
        </div>
    </div>
</div>

and the home page looks like this:

<div id="home" data-role="page" >
    <div data-role="header">
        <h1 class="wrap">Qlearn App Contents</h1>
    </div>
    <div data-role="content">
        <p>Courses:</p>
        <ul id="cList" data-role="listview" data-inset="true">              <li>An error has occurred!</li>
        </ul>
    </div>
    <div data-role="footer" data-position="fixed" class="ui-grid-b">
        <div class="ui-block-a">
            <p>Qlearn||build: 1.0.8</p>
        </div>
        <div class="ui-block-b">
        </div>
        <div class="ui-block-c">
            <div class="ui-btn-right" data-role="controlgroup" data-type="horizontal">
                <a target='_blank' href="#about" data-transition="slideup"  data-role="button" data-iconpos="notext" data-icon="info"  >About</a>
            </div>
        </div>
    </div>
</div>

and I have some javascript to log every change page event

$(document).on("pagechange", function(event){
    console.log("Page Change");
    console.log(event);
});

The following is the code from the click handler and the function called by the click handler:

$(document).on("click", "#cList li a", function(event) {        
    loadModules(this.text); 
    return false;
});

function loadModules(course){
console.log("Starting mod retrieval")
var data = {
  "fn" : "mod",
  "data": course,
  "ajax" : "true"
};
$.ajax({
  type: "GET",
  url: SERVICE_URL,
  data: data,
  contentType: "application/json",
  success: function(response) {
      console.log("Success!");
    console.log(response);
    var i, list = "";
    if($.isArray(response.module)){
            for (i = 0; i < response.module.length; i++) {
                console.log(response.module[i]);
                list += formatModuleListItem(response.module[i]);
                $.mobile.changePage("#modules");
                $("#mList").html(list).listview().listview('refresh');
            }

        }else{
            list = formatModuleListItem(response.module);
            $.mobile.changePage("#modules");
            $("#mList").html(list).listview().listview('refresh');
        }
    }

});
console.log("end of mod retrieval")
}

UPDATE

I have altered the above code to show some changes I made to try and debug this problem. What this has shown me is that sometimes (but not always) when I click on one of the buttons created dynamically on the home page, the changepage event fires twice.

It is only when the event fires twice that this bug occurs, which suggests the second occurrence of the event is being queued and firing when I navigate back to the homepage.

so I wonder if anybody knows if there is a queue of some form that stores changepage events that can be cleared?

Answer:1

I am trying to implement a grid with grouping feature. This is my Model: Model Ext.define('myApp.model.ModelPrueba2', { extend: 'Ext.data.Model', fields: ['id', { name: 'name', type: 'string'...

I am trying to implement a grid with grouping feature. This is my Model: Model Ext.define('myApp.model.ModelPrueba2', { extend: 'Ext.data.Model', fields: ['id', { name: 'name', type: 'string'...

  1. extjs grid grouping multiple columns
  2. extjs grid grouping sort
  3. extjs grid grouping example
  4. extjs grid grouping
  5. extjs grid grouping expand all
  6. extjs grid grouping start collapsed
  7. extjs grid grouping not working
  8. extjs grid grouping collapse all
  9. extjs grid grouping checkbox
  10. extjs grid grouping collapse
  11. extjs grid grouping template
  12. extjs grid grouping tooltip
  13. extjs grid grouping feature
  14. extjs grid grouping column
  15. extjs grid group by multiple fields
  16. extjs grid group header
  17. extjs grid group order
  18. extjs grid group summary
  19. extjs grid group header checkbox
  20. extjs grid grouped column headers

I had an text field where user has to place an url. I need to validate the url whether format is valid.I need to write an reg-exp to find below invalid urls. http://www.google.com//test/index.html //...

I had an text field where user has to place an url. I need to validate the url whether format is valid.I need to write an reg-exp to find below invalid urls. http://www.google.com//test/index.html //...

  1. format validator javascript
  2. validator.js format
  3. validating date format in javascript

I have a site on angular (e.g: app-client.com), where every piece of data comes from another REST API site (e.g: app-api.com). The app-client.com is only a bunch of html, css, and javascript files, ...

I have a site on angular (e.g: app-client.com), where every piece of data comes from another REST API site (e.g: app-api.com). The app-client.com is only a bunch of html, css, and javascript files, ...

  1. twitter oauth without callback url
  2. twitter without oauth
  3. twitter oauth not working
  4. twitter api without oauth

I coded as screenshot to get data from the MySQL database. I added JavaScript codes to change Accept button to Accepted when clicked and Decline button to Declined when clicked. I want to keep those ...

I coded as screenshot to get data from the MySQL database. I added JavaScript codes to change Accept button to Accepted when clicked and Decline button to Declined when clicked. I want to keep those ...

  1. keeping the button pressed