jquery mobile - Find my index.html (first) page in my jQueryMobile history -


i using single page ajax loading of jqmobile. each page own file.

i dynamically create home button on pages when need to. today use <a> tag pointing "index.html". there way can check web app jquerymobile history find first time in history index.html page loaded , call window.history.back(-##); page instead of adding history , navigation.

the code such if there isn't index.html in history, window.location.href page.

function gohome() {    /* function don't know exists, find first occurrence of index.html */   var togo = $mobile.urlhistory.find( 'index.html' )     var toback = $mobile.urlhistory.length -1 - togo;    if ( togo >= 0 )     window.history.back( -1 * toback )   else     $.mobile.changepage( '/index.html' )  } 

if history index.html => profile.html => photos.html magic function of $.mobile.urlhistory.find('index.html') return 0, history length 3, calculation window.history.back( -2 ) index.html page. if find function returned -1 wasn't found , changepage call.

thanks /andy

after reading , reading , reading , not sure reading anymore, wrote function. not sure correct or best solution or if can condensed down.

using call

console.log( 'findhome: ' + findhome( ["", 'index.html'] ) ); 

it search though first entry current index in jquerymobile urlhistory.stack , see if find index page or not. there can decide if want load new page or go -xx 1 in history. way history clean.

function findhome( _home ) { var stk = $.mobile.urlhistory.stack; var ai  = $.mobile.urlhistory.activeindex;  ( var idx=0; idx <= ai; idx++ ) {     var obj = $.mobile.path.parseurl( $.mobile.urlhistory.stack[idx].url );     if(typeof _home == "string")     {         if ( _home == obj.filename )             return( idx - ai );     }     else     {         for(var x in _home)         {             if ( _home[x] == obj.filename )                 return( idx - ai );         }                    } }  return ( 0 );    } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -