Please help someone, below code opening page but not firing event
this._browser = this.inAppBrowser.create('http://www.google.com');
this._browser.on('loadstart').subscribe((event) => {
let alert1 = this._alertCtrl.create({
subTitle: 'load start',
buttons: ['ok!']
});
alert1.present();
});
Related
I migrated from Ionic 4 to Ionic 5 and noticed my toastControllers are not showing the "close" button even if I set up the ToastOptions properties with showCloseButton: true
I fixed it adding explicitly the buttons array like this:
let toast = this.toastCtrl.create({
message: 'User was added successfully',
showCloseButton: true,
position: 'top',
buttons: [
{
text: "close",
handler: () => {
console.log('Close clicked');
}
}
]
});
I am making an ionic app where I need to call to a website(not exist). I am just trying to catch that into the error. But the "exit" event does not get fired.
Code
this.browser = this.iab.create("http://www.randomwebsite.com/", "_blank", this.options);
this.browser.on('exit').subscribe(event => {
console.log("exit -->", event);
}, err => {
console.log("InAppBrowser exit Event Error: " + err);
});
It opens the browser in the app but only shows the 404 page, but dont go further in the error code, so that I can handle it.
Declare cordova in your component
declare var cordova;
Then for the error check you can use the following function
const browser = cordova.InAppBrowser.open('http://randomwebsite.org', '_blank', this.options);
browser.addEventListener('loadstart', function(e) {
// event fires when the InAppBrowser starts to load a URL.
console.log(e);
});
browser.addEventListener('loaderror', function(e) {
// event fires when the InAppBrowser encounters an error when loading a URL.
console.log(e);
browser.close();
});
You can checkout the documentation here.
If I understand the question correctly then the main problem is to catch the error
this.browser = this.iab.create("http://www.randomwebsite.com/", "_blank", this.options);
this.browser.on('loadstop').subscribe(event => {
console.log("exit -->", event);
}, err => {
//once the page loading stops and there is an error it comes here and displays you log.
console.log("InAppBrowser exit Event Error: " + err);
});
exit event is fired when we exit the inAppBrowser
I have this code in my application:
$ionicPopup.alert({
title: $scope.header1,
template: 'The was a problem connecting to the server. Please check your internet connection and try again.'
});
ionic.Platform.exitApp()
what I have noticed is that in Android, the application exits quickly without showing the pop up message. What I wanted to do is execute
ionic.Platform.exitApp()
after the user press the 'Ok' button in the pop-up. ls there something like an "onleave" event in ionic Popup?
The best approach may be to define your own 'OK' button as opposed to leveraging the default dismiss one - that way you can invoke ionic.Platform.exitApp() upon the user clicking/tapping your button.
Example:
import { AlertController } from 'ionic-angular';
constructor(private alertCtrl: AlertController) {
}
presentAlert() {
let alert = this.alertCtrl.create({
title: YourCustomHeader,
//subTitle: 'optional text',
message: 'The was a problem connecting to the server. Please check your internet connection and try again.',
buttons: [
{
text: 'OK',
handler: () => {
ionic.Platform.exitApp();
}
}
]
});
alert.present();
}
Reference: https://ionicframework.com/docs/api/components/alert/AlertController/#usage
Is there any way to change alert direction in ionic 2 ?
const alert = this.alertCtrl.create({
title: 'خطأ',
subTitle: 'GPS والوصول إلى الشبكة غير ممكن.',
enableBackdropDismiss: false,
buttons: [{
text: 'نعم',
handler: () => {
setTimeout(() => this.locate(), 1500);
}
}],
});
I tried and tested some css but fails.
I try but have a difficult way for change this.
Try use ionic AlertController
And set enableBackdropDismiss:false for work like alertCtrl
In an Ionic app, I am using ngCordova's $cordovaInAppBrowser to open Apple Play Store URL. It opens the app store but it does not go into .then. Relevant code:
$cordovaInAppBrowser.open(mktUrl, '_system', {location: 'yes', clearcache: 'yes', toolbar: 'no'}).
then(function(event) { ¬
console.log("inside then"); ¬
$state.go('odetails');
}¬
mktUrl is a app store URL for an app.
It does not generate any error. But it just doesn't work. How can I solve the problem?
Been there.
If you change from _system to _blank, cordova uses same webview as your app container and the promises do work.
I am using this code:
var inAppBrowserOptions = {
location: 'yes',
clearcache: 'no',
hardwareback: 'no'
};
if (!site.toLowerCase().match(/^htt(p|ps):\/\//)) {
site = 'http://' + site;
}
$cordovaInAppBrowser.open(
site,
'_blank',
inAppBrowserOptions
).then(function (event) { // success
//$state.go('')
Toast.show('inAppBrowser success', 'short', 'bottom');
}).catch(function (event) { // error
Toast.show('Error opening site', 'short', 'bottom');
});
$rootScope.$on('$cordovaInAppBrowser:exit', function (e, event) {
Toast.show('inAppBrowser exit', 'short', 'bottom');
});