Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70909

Can't close inAppBrowser on loadStop

$
0
0

@wekas wrote:

I want to close the inAppBrowser window once a certain url has finished loading. User finishes survey.
The code below has the error:
Cannot read property 'close' of undefined
on the line
this.iabRef.close();

Can I not reference this global variable from inside a callback function?
Any ideas?

import { Component } from '@angular/core';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
declare var cordova: any;

@Component({
  selector: 'app-tab1',
  templateUrl: 'tab1.page.html',
  styleUrls: ['tab1.page.scss']
})
export class Tab1Page {
  private iabRef;
  loadStopCounter = 0;

  constructor(private iab: InAppBrowser) { }

  buttonClick(link) {
    console.log('button click');

    const target = '_blank';
    const options = 'location=yes,zoom=no,hideurlbar=yes,hidenavigationbuttons=yes,closebuttoncaption=Click here to return to App,closebuttoncolor=#f04141';

    this.iabRef = cordova.InAppBrowser.open(link, target, options);
    // this.iabRef.close();  This works!!!

    this.iabRef.addEventListener('loadstop', this.loadStop);
  }

  loadStop(params, callback) {
    this.loadStopCounter++;

      if (params.url.substr(params.url.lastIndexOf('/') + 1) === 'formResponse') {
        // This does not work
        this.iabRef.close();
      }
  }
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70909

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>