Phonegap - Navigator.App.Backhistory() Not Working on HTML Back Button

Phonegap - navigator.app.backHistory() not working on HTML back button

I have tried 3 separate things when I faced the same situation:

  • window.history.back()

  • navigator.app.backHistory();

  • History.go(-1);

Individually, none of these solve the problem. I put all 3 things together and much to my surprise it worked. I really don't know what is behind it.

Then I decreased to two functions and removed:

  • window.history.back()

Now I am using this function and it is working fine.

//Works Fine
function onBackKeyDown() {
history.go(-1);
navigator.app.backHistory();
}

Cordova - window.history.back() not working on HTML back button in iOS 9

SOLUTION:

This line resolved my issue :

 history.go(0); 

I have replaced window.history.back() with history.go(0);

Now it is working fine for me in iOS 9

In index.html

   <script type="text/javascript">$.mobile.hashListeningEnabled = false;</script>

Add this in onDeviceReady function:

function onDeviceReady() {
if ( device.platform === "iOS" && parseInt( device.version ) === 9 ) {
$.mobile.hashListeningEnabled = false;
}

if ( !( $.mobile.hashListeningEnabled &&
$.mobile.path.isHashValid( location.hash ) &&
( $( hashPage ).is( ":jqmData(role='page')" ) ||
$.mobile.path.isPath( hash ) ||
hash === $.mobile.dialogHashKey ) ) ) {

// make sure to set initial popstate state if it exists
// so that navigation back to the initial page works properly
if ( $.event.special.navigate.isPushStateEnabled() ) {
$.mobile.navigate.navigator.squash( path.parseLocation().href );
}

$.mobile.changePage( $.mobile.firstPage, {
transition: "none",
reverse: true,
changeHash: false,
fromHashChange: true
} );
} else {
// trigger hashchange or navigate to squash and record the correct
// history entry for an initial hash path
if ( !$.event.special.navigate.isPushStateEnabled() ) {
$window.trigger( "hashchange", [true] );
} else {
// TODO figure out how to simplify this interaction with the initial history entry
// at the bottom js/navigate/navigate.js
$.mobile.navigate.history.stack = [];
$.mobile.navigate( $.mobile.path.isPath( location.hash ) ? location.hash : location.href );
}
}
}

Validation for device OS version (as history.go(0) is working only with iOS 9) Prior to iOS 9 version window.history.back() working perfectly

And now Add this piece of code in place of window.history.back()

if ( device.platform === "iOS" && parseInt( device.version ) === 9 ) {
console.log( "version" + device.version );
console.log( "iOS 9" );
history.go( 0 );
//write your code here
}
else {
window.history.back();
}

To fix this Message "Failed to load webpage with error: CDVWebViewDelegate: Navigation started when state=1" in console add below code in CDVWebViewDelegate.m

In - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType

Method Comment this piece of code shown below:

/*if ([_delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) {
NSDictionary* errorDictionary = @{NSLocalizedDescriptionKey : description};
NSError* error = [[NSError alloc] initWithDomain:@"CDVWebViewDelegate" code:1 userInfo:errorDictionary];
[_delegate webView:webView didFailLoadWithError:error];
}*/

history.back() not working in phonegap ios build

Yes, exactly. In several version iOS, Android ( old), history.back() seem not working. To fix it, you should try this code ( i find it in JQM @@ and it working well for all )

            var nav = window.navigator;
if( this.phonegapNavigationEnabled &&
nav &&
nav.app &&
nav.app.backHistory ){
nav.app.backHistory();
} else {
window.history.back();
}

Phonegap back button not working when cursor focus on a field

The "backbutton" event is fired only when the button is pressed to navigate back, not when used to close the keyboard.

The closest you can get is intercepting the window resize due to the keyboard close and react accordingly:

$(document).ready(function() {
var curWindow = $(window);
var initialHeight = curWindow.height();
curWindow.resize(function() {
console.log("resize: height="+curWindow.height());
if (curWindow.height() == initialHeight) {
// TODO: Keyboard hidden!
}
});
});

Back Button intercepted for ever - Phonegap/Android

the real solution to this question is probably to remove the event with this API:

document.removeEventListener("backbutton", onBackKeyDown, false);

I found it here



Related Topics



Leave a reply



Submit