Hello
I have to open a webapp in a hybrid application. I wanted to use an iframe but I can’t know which link the user has clicked.
If the link leaves the webapp, the chrome app must be lunched. So I use InAppBrowser and I listen to the startload event. If the link leaves the webapp: I do window.stop () and start chrome. But when the user come back into the application, the startload event no longer works.
Example: I’m browsing on Google if I click to the https://m.facebook.com/login link, chrome starts on https://www.facebook.com and when I come back into the application: I can’t see anymore logged events in chrome’s inspector.
My code:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import {InAppBrowser} from 'ionic-native';
import { TabsPage } from '../pages/tabs/tabs';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage = TabsPage;
browser;
constructor(private platform: Platform) {
platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
this.launch();
});
}
launch() {
this.platform.ready().then(() => {
this.browser = new InAppBrowser('https://www.google.com', '_self','location=no,toolbar=no');
this.browser.on("loadstart").subscribe(data => {
console.log("loadstart");
console.log(data);
if(data.url == "https://m.facebook.com/login/"){
this.browser.executeScript({ code: 'window.stop();' });
window.open('https://www.facebook.com','_system');
}
});
this.browser.on("exit").subscribe(data => {
console.log("exit");
this.platform.exitApp();
console.log(data);
});
});
}
}
My logs:
DEVICE READY FIRED AFTER 191 ms
main.js:1 Native: tried calling t.styleDefault, but the t plugin is not installed.C @ main.js:1
main.js:1 Install the t plugin: 'ionic plugin add cordova-plugin-statusbar'C @ main.js:1
main.js:1 Native: tried calling t.hide, but the t plugin is not installed.C @ main.js:1
main.js:1 Install the t plugin: 'ionic plugin add cordova-plugin-splashscreen'C @ main.js:1
main.js:10 loadstart
main.js:10 Objecttype: "loadstart"url: "https://www.google.com/"__proto__: Object
main.js:10 loadstart
main.js:10 Objecttype: "loadstart"url: "https://www.google.be/?gfe_rd=cr&ei=7WRRWK71Morc8Afp-rOIBg"__proto__: Object
main.js:10 loadstart
main.js:10 Object {type: "loadstart", url: "https://www.google.be/search?site=&source=hp&ei=7W…...0...1c..64.mobile-gws-hp..0.1.62.1.i4FG1KWU7rg"}
main.js:10 loadstart
main.js:10 Objecttype: "loadstart"url: "https://m.facebook.com/login/"__proto__: Object
Can you help me please?
Thank’s for reading.
Pierre.