Cordova InAppBrowser 不在外部打开 url

Cordova InAppBrowser do not open the url externally

我正在尝试打开外部 URL www.google.co.in via cordova InAppBrowser. But the browser is appending this URL to the server and port address. So the end URL which is cordova browser trying to open become http:localhost:8000/www.google.co.in

我正在使用 ionic cordova 运行 浏览器 命令对此进行测试。

Below is the code (Ionic 5.0.0)

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

declare var window: any;

@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {

  loading: HTMLIonLoadingElement;

  constructor(
    private serviceProvider: ServiceProvider,
    private elementRef: ElementRef,
    private router : Router,
    private menu: MenuController,
    private loadingController: LoadingController,
    private platform: Platform,
    private inAppBrowser: InAppBrowser) { }

  ngOnInit() { 
    this.menu.enable(false);
    this.login();
  }

  public login() {
    this.platform.ready().then(() => {
      this.openInAppBrowser().then(success => {
          alert(success);
      }, (error) => {
          alert(error);
      });
  });
  }

  public openInAppBrowser(): Promise<any> {
    return new Promise(function(resolve, reject) {  
      var options: string = "location=no,clearcache=yes,clearsessioncache=yes"
      var browserRef = window.cordova.InAppBrowser.open("www.google.co.in", "_blank", options);
      browserRef.addEventListener("loadstart", (event:any) => {
        alert(event);
      });
      browserRef.addEventListener("exit", function(event) {
          reject("Completed");
      });
  });
  } 

Here is my app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { PopoverPageModule } from './popover/popover.module';
import { HttpClientModule } from '@angular/common/http';
import { GlobalFunctions } from '../providers/global-functions';
import { AuthGuard } from '../providers/auth-guard';

import { ServiceProvider } from '../providers/service';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, HttpClientModule, IonicModule.forRoot(), AppRoutingModule, PopoverPageModule],
  providers: [
    ServiceProvider,
    GlobalFunctions,
    AuthGuard,
    StatusBar,
    SplashScreen,
    InAppBrowser,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

有人知道这里出了什么问题吗?

根据文档,您需要使用这个:

this.inAppBrowser.create("www.google.co.in", "_blank", options)

而不是

window.cordova.InAppBrowser.open("www.google.co.in", "_blank", options)

参考文献:
https://ionicframework.com/docs/native/in-app-browser/
https://ionicframework.com/docs/v3/native/in-app-browser/

这是一个简单的错误。我没有将 http:// 添加到 URL。它应该是 http://www.google.co.in 而不是 www.google.co.in