簡體   English   中英

離子 - InAppBrowser 不斷打開系統外部 web 瀏覽器不是應用內之一

[英]Ionic - InAppBrowser keep opening system external web browser not in-app one

在 Ionic App 頁面( ionic serve的 localhost:8100 頁面)中,開發者控制台記錄了警告

本機:未安裝 InAppBrowser 或您正在瀏覽器上運行。 回退到 window.open。

web 瀏覽器中發生的事情實際上也發生在我在設備上測試它時( ionic cap run android )。 該網站是在設備的默認外部 web 瀏覽器上打開的,而不是應用程序的“應用內”web 瀏覽器。 我認為是因為在構建過程中從未將InAppBrowser安裝到設備上。 但我不知道為什么。

以下是我的代碼的最簡化的可行版本。 隨時詢問是否需要更多。


main.ts

if (environment.production) enableProdMode();
platformBrowserDynamic().bootstrapModule(App).catch(err => console.log(err));

應用程序.ts

@NgModule({
  declarations: [Comp],
  entryComponents: [],
  imports: [
    IonicModule, CommonModule, FormsModule, BrowserModule, IonicModule.forRoot(), Routing
  ],
  providers: [
    InAppBrowser, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [Comp]
})
export class App {}

路由.ts

const routes: Routes = [
  { path: '', loadChildren: () => import('./home').then(m => m.Home) }
];
@NgModule({
  imports: [RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })],
  exports: [RouterModule]
})
export class Routing {}

組件.ts

@Component({
  selector: 'app-root', templateUrl: 'component.html', styleUrls: ['component.scss'],
})
export class Comp {}

主頁.ts

@NgModule({
  imports: [
    CommonModule, FormsModule, IonicModule, RouterModule.forChild([{path: '', component: Page}])
  ],
  declarations: [Page]
})
export class Home {}

頁面.ts

export class Page{

  constructor(private iab : InAppBrowser, private platform : Platform) {}

  ngOnInit(){
    this.iab.create(URL, _blank); //tried _self too. not working
  }
}

在安裝 package 之前忘記安裝插件。 我對缺乏信息表示歉意。

ionic cordova plugin add cordova-plugin-inappbrowser

但是,不便之處應該得到更好的處理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM