【问题标题】:Ionic 3- how to open external url in device default browserIonic 3-如何在设备默认浏览器中打开外部 url
【发布时间】:2018-08-02 10:12:48
【问题描述】:

我想在设备默认浏览器中打开外部 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 文件中添加了提供程序

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

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

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

配置

1.离子 - v3

2。角 - v6

3.科尔多瓦-v8

【问题讨论】:

    标签: cordova ionic3 cordova-plugins angular6 inappbrowser


    【解决方案1】:

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

    <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
          }
    

    【讨论】:

    • 我没有代码问题。每当我在 app.module.ts 中添加代码作为提供程序时,应用程序就会崩溃
    【解决方案2】:

    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();
    });
    }
    

    【讨论】:

    • java.lang.NullPointerException:尝试在 org.apache.cordova 的空对象引用上调用虚拟方法“void android.widget.ImageView.setAnimation(android.view.animation.Animation)”。 splashscreen.SplashScreen$4.run(SplashScreen.java:230) 如果我删除了插件.. 除了在浏览器中打开 url 之外一切正常。
    • 你在哪里调用inappbrowser?只是在打开应用程序时?
    • 每当我将它作为提供者添加到 app.module.ts 中时,应用都会崩溃
    • 但是你在哪里调用这个inappbrowser?一旦启动画面消失?我认为启动画面和第一页之间似乎存在问题
    猜你喜欢
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 2021-09-11
    • 1970-01-01
    • 2017-10-03
    • 2018-08-21
    • 2014-12-29
    相关资源
    最近更新 更多