0

hi I have some jQuery Mobile and pageshow works fine (it's blip bugged but it works fine) like this:

$(document).off('pageshow').on('pageshow', function () { 
   console.log('it happened');
});

NB: I have had numerous (READ: weeks lost) problems with caching, so I am afraid despite all information to the contrary the off() has to stay. You will argue with me, I will keep off() and I will be right.

ok but when I change it to

$(document).off('pagebeforeshow').on('pagebeforeshow', function () { 
   console.log('it happened');
});

it doesn't run. Now I know that you are supposed to be doing something like

$(document).off('pagebeforeshow').on('pagebeforeshow', '#somediv', function () { 
   console.log('it happened');
});

but I don't want it to be on just that div I want it to be on the whole document.

user26676
  • 270
  • 2
  • 18
  • I have to use it, we're open source so have to use open source dependencies. It's basically a secret lying browser in a browser, once u get to that it can be used – user26676 Jul 09 '14 at 10:39
  • no need to use closed source dependencies. just write your own for the bits you're using jQm for. If you can't figure out how jqm does something, look at jqm source. Most things jQm does, it's relatively easy to come up with alternative solutions for (unlike jquery). – user1094553 Jul 09 '14 at 11:31
  • 1
    what about attaching to the whole `body`? It's working in my test `$(document).off('pagebeforeshow').on('pagebeforeshow', 'body', function ()` – Sga Jul 09 '14 at 11:43
  • it doesn't fire (as pageshow does) when I navigate back and forth – user26676 Jul 09 '14 at 12:20
  • Here is a fiddle: http://jsfiddle.net/ezanker/GM7qg/2/ both events seem to fire properly as do the new pagecontainer events. Can you reproduce the issue in a fiddle? – ezanker Jul 09 '14 at 14:56

1 Answers1

0

You can test when you leave a specific page like this ( worked in my case ):

--> Start a loop function ( setInterval ) that tests every 2 sec if you are still on that page, and if not ( it means that you just left the page ) execute only once a function

Here is the code:

<script>$('#YOUR_PAGE').bind('pageshow', function(data) { 
      var repeat = setInterval(function() {
      var page_path = $.mobile.path.parseUrl(window.location).toString().toLowerCase() ;
      var page_page = page_path.split("#"); 
          if ( page_page[1]  != "YOUR_PAGE"){

          ...
          DO YOUR THING
          ...

          clearInterval(repeat);
               }
          }, 2000);
      });
</script>