jQuery and jQueryMobile seem to load a page multiple times. However, for me it is essential that a certain initialization code is not executed more than once. I would expect that one of the following would do:
$(document).ready(function(e) { ... });
or
$(document).on('pageinit', '#myPage', function(e) { ... });
but they all fire many times-even if setup inside the section
<div data-role="page" id="myPage"> ...
Even virginity variables do not work, i.e.
var virginity_f = true;
$(document).ready(function (e) {
console.log("virginity.before: " + virginity_f);
if( virginity_f == false ) return;
virginity_f = false;
console.log("virginity.after: " + virginity_f);
...
}
produces a console log something like:
virginity.before: true
virginity.after: false
virginity.before: true
virginity.after: false
What is the solution for having a code fragment being executed exactly once in the environment of jQuery and jQueryMobile?