【问题标题】:Ionic - InAppBrowser keep opening system external web browser not in-app oneIonic - InAppBrowser 不断打开系统外部 Web 浏览器而不是应用内浏览器
【发布时间】:2022-01-21 13:41:49
【问题描述】:

在 Ionic App 页面(ionic serve 的 localhost:8100 页面)中,开发者控制台记录了警告

Native:未安装 InAppBrowser 或您正在浏览器上运行。回退到 window.open。

Web 浏览器中发生的事情实际上也发生在我在设备上测试时 (ionic cap run android)。该网站是在设备的默认外部网络浏览器上打开的,而不是应用程序的“应用内”网络浏览器。我认为是因为在构建过程中从未将InAppBrowser 安装到设备上。但我不知道为什么。

以下是我的代码的最简化的可行版本。如有更多需要,请随时询问。


main.ts

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

app.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 {}

home.ts

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

page.ts

export class Page{

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

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

【问题讨论】:

  • 您需要将选项传递给您的函数。
  • this.iab.create(url, '_blank', options); 使用这个。
  • 好的,谢谢您的回复。我去看看
  • 对不起。我找不到任何可用的选项来强制应用程序在 inappbrowser 中打开页面,或者至少通知它是否未安装。我尝试了 _self 和 _blank。两者都不起作用
  • 你先安装了吗?我觉得设备还没有准备好使用插件,里面app.component.ts试试this.platform.ready().then(() => {this.iab.create("url_here", _blank);});

标签: angular ionic-framework ionic-native inappbrowser ngx-bootstrap


【解决方案1】:

安装包之前忘记安装插件了。对于信息不足,我深表歉意。

ionic cordova plugin add cordova-plugin-inappbrowser

但不便之处应该得到更好的处理。仍然想知道为什么缺少插件不被视为错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多