【问题标题】:ionic InAppBrowser Events Not Firing离子 InAppBrowser 事件未触发
【发布时间】:2019-11-11 13:42:25
【问题描述】:

我正在使用 ionic cordova 应用内浏览器插件

constructor(private iab: InAppBrowser){
      const browser = this.iab.create('https://www.sample.com'_self',{location:'no'}); /*3*/

this.browser.on('loadstart', event => {
    alert('loadstart event'); // not fired
    });
    this.browser.on('loaderror', event => {
      alert(' error'); // not fired
      });
    this.browser.on('exit', event => {
      alert('exit event'); // not fired
    });
}

但是 loadstart、loaderror、exit 事件不起作用。
谢谢..!

【问题讨论】:

    标签: cordova ionic-framework cordova-plugins inappbrowser


    【解决方案1】:

    使用目标"_blank" 而不是"_self",例如:

    const browser = this.iab.create(
    'https://www.sample.com',
    '_blank',
    {location:'no'}
    );
    

    【讨论】:

      【解决方案2】:

      如果您使用的是最新的 ionic 版本,那么以下是为 inappbrowser 调用每个事件的方式:

      openInAppBrowser(){
      const options:any = {
            closebuttoncolor: "#ffffff",
            lefttoright: 'yes',
            hideurlbar: 'yes',
            fullscreen: 'yes',
            hardwareback: 'no',
            toolbarcolor: '#145a7b',
            zoom: 'no',
            useWideViewPort: 'no',
            hidenavigationbuttons: 'yes',
            footer: 'no',
            message: "Hello",
            toolbar : 'no',
            location:'no'
          }
      
       let browser = this.iab.create(url, '_blank', options); 
      
       browser.on('loadstop').subscribe(async event =>{
           //your logic goes in here....
      });
      
       browser.on('loadstart').subscribe(async event =>{
           //your logic goes in here....
      });
      
       browser.on('loaderror').subscribe(async event =>{
           //your logic goes in here....
      });
      
       browser.on('beforeload').subscribe(async event =>{
           //your logic goes in here....
      });
      
       browser.on('message').subscribe(async event =>{
           //your logic goes in here....
      });
      }
      
      

      【讨论】:

      【解决方案3】:

      首先检查 platform.ready() 事件在计算您的进程之后。

      constructor(private iab: InAppBrowser){
      platform.ready().then(() => {
        if (typeof cordova !== 'undefined') {
      
      //Do your process
      
      const browser = this.iab.create('https://www.sample.com'_self',{location:'no'}); /*3*/
      
      this.browser.on('loadstart', event => {
          alert('loadstart event'); // not fired
          });
          this.browser.on('loaderror', event => {
            alert(' error'); // not fired
            });
          this.browser.on('exit', event => {
            alert('exit event'); // not fired
          });
      
          });
         }
        }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多