3

我想在设备默认浏览器中打开外部 url。就像对于 android 它应该在 chrome 中打开,对于 ios 它应该在 safari 中打开。

最初,当我尝试window.open(url,"_system")使用 android 时它运行良好。当我在ios中尝试时,它不起作用。

经过一番研究,我知道由于 safari 的弹出块性质,它没有打开。然后我禁用了弹出块设置。问题仍然存在。后来我才知道我需要安装 InAppBrowser 插件才能使其工作。

因此我按照以下步骤

ionic cordova plugin add cordova-plugin-inappbrowser

npm install --save @ionic-native/in-app-browser

在 app.module.ts 文件中添加了提供程序

安装插件后,应用程序开始在 android 设备上崩溃。(未在 ios 上检查)。

我不知道原因。如果我删除插件,应用程序正在运行,但现在我也无法在 android 中打开 url。

谁能告诉我如何在android和ios中打开外部url?

配置

1. 离子 - v3

2. 角 - v6

3.科尔多瓦-v8

4

2 回答 2

2

这是使用App Browser Plugin在 V3 中为我工作的解决方案

<button ion-button block clear (click)="openWebpage(url)">Open Webpage</button>

openWebpage 方法是这样的

 openWebpage(url: string) {
        const options: InAppBrowserOptions = {
          zoom: 'no'
        }

        // Opening a URL and returning an InAppBrowserObject
        const browser = this.inAppBrowser.create(url, '_self', options);

       // Inject scripts, css and more with browser.X
      }
于 2018-08-02T16:06:25.310 回答
1

在config.xml中更改它

<preference name="FadeSplashScreen" value="false" />
<preference name="AutoHideSplashScreen" value="false" />

并在app.component.ts

initializeApp() {
this.platform.ready().then(() => {
  // Okay, so the platform is ready and our plugins are available.
  // Here you can do any higher level native things you might need.
  this.statusBar.styleDefault();
  this.splashScreen.hide();
});
}
于 2018-08-02T10:56:00.303 回答