Hello everyone!
I’m so new using ionic, but I’ll try to express myself as well as I can.
I’m developing an app that has an iFrame that change the src when the user press differents buttons that are placed in the toolbar. I need the toolbar always on top (that’s why I’m using an iframe). I want to go back in the iFramne history when the user press the back button (android and iOs).
This is the code of app.component.ts
constructor(public platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
this.initializeApp(platform);
document.addEventListener("backbutton", this.onBackPressed, false);
});
}
public onBackPressed(){
var iframe = document.getElementById("embed-web");
var iWindow = (<HTMLIFrameElement>iframe).contentWindow;
console.log("==========================================");
console.log("Lenght of iFrame: "+ iWindow.history.length);
if(iWindow.history.length>0)
iWindow.history.go(-1);
else
this.platform.exitApp();
console.log("BACK BUTTON PRESSED");
}
As you can see, I had created an EventListener that wait until the user press the back button on Android and call the function onBackPressed. But when I press the back button the app closes and nothing happen…
This is the console output.
Could you help me?
Thank’s for all!