3
votes

Comment détecter l'URL redirigée dans Cordova inappbrowser et fermer le navigateur

J'utilise l'inappbrowser cordova pour mon application ionique. J'ai besoin de détecter quand l'URL redirige vers http: //xx.success.html ou http: //xx.failure.html

mon code:

Error in Success callbackId: InAppBrowser780208391 : TypeError: Object(...) is not a function
cordova.js:310 TypeError: Object(...) is not a function
    at InAppBrowserObject.close (vendor.js:81063)
    at SafeSubscriber._next (main.js:411)
    at SafeSubscriber.__tryOrUnsub (vendor.js:20899)
    at SafeSubscriber.next (vendor.js:20846)
    at Subscriber._next (vendor.js:20786)
    at Subscriber.next (vendor.js:20750)
    at Channel.fire (cordova.js:843)
    at InAppBrowser._eventHandler (inappbrowser.js:48)
    at cb (inappbrowser.js:108)
    at Object.callbackFromNative (cordova.js:291)

ne fonctionne pas et inAppBrowserObject.close () code > n'est jamais appelé.

erreur dans la console de développement Chrome:

public openWithCordovaBrowser(url: string) {
    //where are events triggered (_self,_blank,_window)?
    let target = "_self"; 

    let inAppBrowserObject = this.inAppBrowser.create(url, target, this.inAppBrowserOptions);

                //When the page is success, close inappbrowser
    if (inAppBrowserObject.on('loadstart').subscribe) {
      inAppBrowserObject.on('loadstart').subscribe((e: InAppBrowserEvent) => {
        if (e && e.url) {
          if (e.url.includes('success.html')) {
            inAppBrowserObject.close(); //not reached?
          }
        }
      });
    }

               //When the InAppBrowser is closed, check and use the last viewed URL
    if (inAppBrowserObject.on('exit').subscribe) {
      inAppBrowserObject.on('exit').subscribe((e: InAppBrowserEvent) => {
        if (url) {
        console.log('exit: ' + e); //this is reached
        }
      });
    }
  }

Mais la fermeture du navigateur appelle console.log ('exit:' + e); code>

mon objet inAppBrowser ressemble à ceci: entrez la description de l'image ici


2 commentaires

Pourriez-vous publier la sortie pour nAppBrowserObject.on ('loadstart')?


ajouté la sortie de débogage


3 Réponses :


1
votes

On dirait que vous faites référence à deux instances distinctes ici. Essayez avec la cible comme «_blank». La documentation Cordova dit:

_self: S'ouvre dans Cordova WebView si l'URL est dans la liste blanche, sinon il s'ouvre dans InAppBrowser.

_blank: s'ouvre dans InAppBrowser.

Référence: https: //cordova.apache. org / docs / fr / latest / reference / cordova-plugin-inappbrowser /


0 commentaires

4
votes

il s'agit d'un problème lié au plugin cordova. Lien du problème


J'ai supprimé les plugins cordova et npm 5.xx et installé 4.20.0. Cela a résolu le problème.

supprimer les anciennes versions:

import { InAppBrowser, InAppBrowserObject } from '@ionic-native/in-app-browser'

installer la version 4.20.0:

import { InAppBrowser, InAppBrowserObject } from '@ionic-native/in-app-browser/ngx'

importation également modifiée de

ionic cordova plugin add cordova-plugin-inappbrowser
npm install --save @ionic-native/in-app-browser@4.20.0

à

cordova plugin remove cordova-plugin-inappbrowser
npm uninstall @ionic-native/in-app-browser --save


0 commentaires

1
votes

Cette solution fonctionne bien avec cordova 8 et ionic 3.20 .. Auriez-vous besoin d'un .show pour être appelé. Semble être lié au fait que l'écran n'a jamais été en état .show - peut-être? Si votre navigateur est masqué par défaut.

  const iabrowser = this.inAppBrowser.create(this.signupUrl,'_self',iabOptions);

  this.loader.presentLoading();
    iabrowser.on('loadstart').subscribe(event =>{
    console.log(event);
    iabrowser.executeScript({code: "alert('loadstart! I am an alert box!!')"});
    if (event && event.url) {
        if (event.url.includes('/app/main/login')) {
            iabrowser.close();
        }
    }
    iabrowser.show();
  });
  iabrowser.on('loadstop').subscribe(event =>{
    console.log(event);
    this.loader.dismissLoading();
  });


0 commentaires