【问题标题】:managing browser history in iframe onclick hardware back button ionic 2在 iframe onclick 硬件后退按钮 ionic 2 中管理浏览器历史记录
【发布时间】:2018-05-04 03:52:33
【问题描述】:

我是 ionic 框架的新手,无法在 Iframe 中管理硬件后退点击功能。我正在使用 iframe 加载某些 url。单击硬件后退按钮时,我应该能够导航回浏览器历史记录页面。但是每当我点击硬件时,它就会退出应用程序。

`<iframe #iframe id="iframe" style="height: 100%;width: 100%;" src="your url"></iframe>`
@ViewChild('iframe') iframe:ElementRef;

constructor(public platform:Platform,public nav:Nav){

  platform.registerBackButtonAction(() => {
     if(this.nav.canGoBack()){
        this.iframe.nativeElement.contentWindow.history().back();
     }
  });
}

【问题讨论】:

    标签: ionic2 angular2-template


    【解决方案1】:

    你可以使用window.history.back():

      ionViewDidLoad() {
        this.navBar.backButtonClick = (e: UIEvent) => {
          window.history.back();
        }
        this.initializeBackButtonCustomHandler();
      }
    
      ionViewWillLeave() {
        // Unregister the custom back button action for this page
        this.unregisterBackButtonAction && this.unregisterBackButtonAction();
      }
    
      initializeBackButtonCustomHandler(): void {
        this.unregisterBackButtonAction = this.platform.registerBackButtonAction(function(event){
          window.history.back();
    
        }, 101); // Priority 101 will override back button handling (we set in app.component.ts) as it is bigger then priority 100 configured in app.component.ts file */
      }
    

    有关此方法的更多信息可以找到here。

    【讨论】:

      猜你喜欢
      • 2015-05-18
      • 2012-08-19
      • 2010-11-01
      • 2018-10-02
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      相关资源
      最近更新 更多