Is it possible to override done button functionality? i need to just hide inappbrowser on done button as when show same the last visit url next time.
First, you can hide the Done button in Android (setting option Footer = false) but not in iOS. This makes sense because in Android you have the Back button to close the browser and come back to the app. But iOS does not have back button, so the user needs a graphical button for it.
Second, you can't override the button functionality, but you can add events to the browser, to run your code when something happens, for example when the browser is closed, all of this is explained in the Github page:
https://github.com/apache/cordova-plugin-inappbrowser
browser. addEventListener( "exit", () => {
// Here do something
}) ;
Add closebuttoncaption=Done
Example:
cordova.InAppBrowser.open(url, '_blank', 'location=no,toolbar=yes,toolbarposition=top,closebuttoncaption=Done);
Related
I tried adding function to override current back button behaviour, which is exactly the same as pressing back button (left arrow) in browser. This often goes to the view that is forward instead of going back. I understand that this is how WebView would handle back button action if it is not override.
I was surprised that Android back button doesn't work the same as ion-nav-view standard back button, so I found the code that is responsible in ionic.bundle.js:
// Triggered when devices with a hardware back button (Android) is clicked by the user
// This is a Cordova/Phonegap platform specifc method
function onHardwareBackButton(e) {
console.log('check'); //this never fires
var backView = $ionicHistory.backView();
if (backView) {
// there is a back view, go to it
backView.go();
} else {
// there is no back view, so close the app instead
ionic.Platform.exitApp();
}
e.preventDefault();
return false;
}
console.log('check2'); //this fires
$ionicPlatform.registerBackButtonAction(
onHardwareBackButton,
IONIC_BACK_PRIORITY.view
);
I tested it on Galaxy S5.
Any hints how to make this work?
Why are you not using : $ionicHistory.goBack() instead of backView.go(); ?
From doc goBack is the way to navigate through history
I think you are adding the the back view as a new view upon the stack by calling
backView.go();
you should, instead call
$ionicHistory.goBack();
Is it possible you're using Ionic View to run the app? If so, that's been one of the many different-than-native issues that I've run into while using Ionic View. I couldn't get the back button behavior to work as intended within Ionic View, among other things.
I've since switched to testing my app with others using Google Play Alpha/Beta Testing. That will get the app running on every tester's device the way it will actually appear.
Even though I had no errors like:
cordova is undefined
I added the following to my index.html and it started working
<script src="cordova.js"></script>
I have an simple app that onDeviceReady starts the InAppBrowser and shows a website. Then The InappBrowser will be closed when a specific event occurs.
As you may know, on Android platform pressing "back button" closes the InAppBrowser which I want to be prevented. I want to InAppBrowser be shown to user until that event occurs and user be unable to close the InAppBrowser.
Be noted that I am not talking about hardwareback options. hardwareback is a useful option which lets user goes back in history of his/her navigation by pressing "back button" but at the first page (when there is nothing left in history), it closes InAppBrowser while I want InAppBrowser still remains open.
In the latest InAppBrowser versions you still have to change the onBackPressed function in the JAVA code of InAppBrowserDialog.java plugin code:
public void onBackPressed () {
if (this.inAppBrowser == null) {
this.dismiss();
} else {
// better to go through the in inAppBrowser
// because it does a clean up
if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) {
this.inAppBrowser.goBack();
} else {
// this.inAppBrowser.closeDialog();
}
}
}
I don't like this approach I have asked a feature on GitHub; you can follow it on GitHub here: https://github.com/apache/cordova-plugin-inappbrowser/issues/530
I realize this question is fairly old but I stumbled upon it when I was searching for the answer myself.
You can edit the InAppBrowserDialog.java file (plugins>cordova-plugin-inappbrowser>src>android) to change the behavior of the back button once it's pressed.
this.inAppBrowser.closeDialog()
Comment out the above piece of code in the onBackPressed() method, and this will prevent the browser from being closed on hardware back, while still maintaining the navigation functionality.
Actually, there is no solution available to prevent the inappbrowser from closing when the hardware back button is pressed. The only thing you can do is reload the same URL in the inappbrowser again after a minimum delay of 500ms. The delay is important, otherwise, the inappbrowser window won't be shown.
I am creating an application using the framework cordova. I need to intercept the "Back" button of the phone itself in order to perform the various aoperazioni, for example closing a modal dialog. The problem is that now, once you open the modal, I can not close it by pressing the back button. What happens is that you close any application. How could I do to intercept this event which is not part of the app but the phone? I refer to the actual button of a smartphone. Thanks for your help.
You can achieve this with Javascript using Phonegap's Event API
document.addEventListener("backbutton", function (e) {
// your code
} , false);
Have you read the docs?
Here's what you need: http://docs.phonegap.com/en/4.0.0/cordova_events_events.md.html#backbutton
I'm developing a app using angularjs and ionic framework. It has a logout option also. When i logout from my app it goes straight to the home page.But if i press the back button it'll go to page that can be accessed only if you are logged in. How can i create a option to close the app if you press the back button from the home page? I use angularjs.
I used this way but did not work
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('/templates/playlists')){
/*
Event preventDefault/stopPropagation not required as adding backbutton
listener itself override the default behaviour. Refer below PhoneGap link.
*/
//e.preventDefault();
navigator.app.exitApp();
}
else {
navigator.app.backHistory()
}
}, false);
Your code is good.
But, I'm not sure about the second line : are you sure that the active page id is /templates/playlists ?
Normally, the value you should pass to the $.mobile.activePage.is function should contain a page id (which could be retrieved like this : $.mobile.activePage.attr('id')).
(by the way, I don't know which of jQuery Mobile you are using, but the $.mobile.activePage.is was deprecated).
Okay, I'm making app with phonegap, and in the app I have a home button which goes to the home screen of the app, but if I click the back key after I touched the home button it goes to the page I was on before I clicked the home button, is it possible to reset the history when you navigate to the homepage? Thanks :)
You can't clear the history.
You can listen for back button event:
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
// Handle the back button
}
and stop the propagation.
The link below recommends using location.replace(url) instead of replacing the history completely, which I'm not sure is possible anyway. However, given that this is a constrained environment (an app) wiping the history might make sense - again, if possible if you're in an app.
Clear browser history
Alternatively, couldn't you just remove the back key and replace it with a custom one?
inside the event handler of the button which takes you to home:
startActivity(activityForHome); //I guess you already have this line
finish(); //now add this line