Hashchange causing phonegap application to crash?

I use ajax in my phonegap application to load content for different pages. I also use onhashchange to enable button functionality.

At first, everything works fine, but if I click 3 different links (and trigger 3 hash changes), then my application will completely crash, stop responding, and then eats up all my memory.

Below is the hash change code, anyone has any idea why this could be a crash / memory leak?

$('a.ajax').click(function () { location.hash = $(this).attr('href').match(/(^.*)\./)[1] return false }) function hashChange() { var page = location.hash.slice(1) if (page != "" && window.location.hash) { wrap.load('pages/' + page + ".html .page-wrapper", function(){ closeMenu(); }) }else{ wrap.load('pages/Welcome.html .page-wrapper', function(){ closeMenu(); }) } } // check for hash change if ("onhashchange" in window) { $(window).on('hashchange', hashChange).trigger('hashchange') } else { // lame browser var lastHash = '' setInterval(function () { if (lastHash != location.hash) hashChange() lastHash = location.hash //contentScroller.scrollTo(0,0); }, 100) } 

Just to notice, I get the following error in the xCode console and I run version 2.9 of phonegap

CDVWebViewDelegate: Navigation starts when state = 1

Thanks!

+4
source share
1 answer

I was not completely sure what caused the crash, but I decided to use this plugin http://benalman.com/projects/jquery-hashchange-plugin/ , and now everything works fine

 var wrap = $('#contentScroller .scroller'); $('a.ajax').click(function () { location.hash = $(this).attr('href').match(/(^.*)\./)[1]; return false; }); $(window).hashchange(function () { var page = location.hash.slice(1); if (page !== "" && window.location.hash) { wrap.load('pages/' + page + ".html .page-wrapper", function () { closeMenu(); }); } else { wrap.load('pages/Welcome.html .page-wrapper', function () { closeMenu(); }); } }); 
0
source

Source: https://habr.com/ru/post/1502600/


All Articles