(Ionic-Android)吐司消息在inappbrowser中不起作用

时间:2019-01-17 04:08:10

标签: android typescript ionic-framework ionic3 ionic-native

当我按下浏览器中的后退按钮时,我试图显示吐司消息。这是我的代码:

    export class HomePage {
  options : InAppBrowserOptions = {
    location : 'no',//Or 'no' 
    hidden : 'no', //Or  'yes'
    clearcache : 'yes',
    clearsessioncache : 'yes',
    zoom : 'no',//Android only ,shows browser zoom controls 
    hardwareback : 'yes',
    mediaPlaybackRequiresUserAction : 'no',
    shouldPauseOnSuspend : 'no', //Android only 
    closebuttoncaption : 'Close', //iOS only
    disallowoverscroll : 'yes', //iOS only  
    toolbar : 'yes', //iOS only
    enableViewportScale : 'no', //iOS only 
    allowInlineMediaPlayback : 'no',//iOS only 
    presentationstyle : 'pagesheet',//iOS only 
    fullscreen : 'yes',//Windows only  
};

counter=0;

  constructor(public toast: Toast, public platform: Platform, public navCtrl: NavController, private theInAppBrowser: InAppBrowser) {
    platform.registerBackButtonAction(() => {
      if (this.counter == 0) {
        this.counter++;
        this.presentToast();
        setTimeout(() => { this.counter = 0 }, 3000)
      } else {
        // console.log("exitapp");
        platform.exitApp();
      }
    })
    this.openWithCordovaBrowser("https://google.com/");

  }

  public openWithCordovaBrowser(url : string){
      let target = "_self";
      const browser = this.theInAppBrowser.create(url,target,this.options);
      browser.on('exit').subscribe(() => {
        this.platform.exitApp();         
   });
  }  

  presentToast() {
    let toast = new Toast();
    toast.show(`press again to exit`, '3000', 'center').subscribe(
      toast => {
        console.log(toast);
      }
    );
  }
}

但是,它不起作用。当我按下“后退”按钮时,烤面包消息未正确显示。但是,当我按下双向返回功能时,退出是可行的。

如何在InAppBrowser中使烤面包工作?

0 个答案:

没有答案