在inAppBrowser里面的cordova android inAppBrowser

问题描述 投票:0回答:2

我在我的cordova应用程序中打开网页

cordova.InAppBrowser.open('...', '_self','location=no,hidden=yes');

是否可以使用InAppBrowser _blank在此页面上打开链接?

现在我有一个错误

InAppBrowser does not support Cordova API calls

谢谢

cordova inappbrowser
2个回答
1
投票

好吧,默认情况下InAppBrowser插件安装在Cordova应用程序中,因此无需添加任何显式插件。

使用此代码打开

 <input type="submit" value="submit" src="img/btn.png" onclick="window.open('https://yourexample.com','_blank','location=no','closebuttoncaption=Return','EnableViewPortScale=no');"/>

更新:

onclick="window.open('https://example.com','_blank','location=yes','closebuttoncaption=Return','EnableViewPortScale=no');"/>
  • _self:如果URL在白名单中,则在Cordova WebView中打开,否则在InAppBrowser中打开。
  • _blank:在InAppBrowser中打开。
  • _system:在系统的Web浏览器中打开。

InAppBrowser的选项。可选,默认为:location = yes。 (串)

选项字符串不得包含任何空格,并且每个要素的名称/值对必须用逗号分隔。功能名称不区分大小写。所有平台都支持以下值:

  • location:设置为yes或no以打开或关闭InAppBrowser位置栏。仅限Android:
  • hidden:设置为yes以创建浏览器并加载页面,但不显示它。加载完成后,loadstop事件将触发。省略或设置为no(默认值)以使浏览器打开并正常加载。
  • clearcache:设置为yes以在打开新窗口之前清除浏览器的cookie缓存
  • clearsessioncache:设置为yes以在打开新窗口之前清除会话cookie缓存
  • zoom:设置为yes以显示Android浏览器的缩放控件,设置为no以隐藏它们。默认值为是。
  • hardwareback:设置为yes以使用硬件后退按钮向后导航InAppBrowser的历史记录。如果没有上一页,则InAppBrowser将关闭。默认值为yes,因此如果希望后退按钮只是关闭InAppBrowser,则必须将其设置为no。

有关https://github.com/apache/cordova-plugin-inappbrowser的更多信息


0
投票

使用create()方法而不是open()。我不知道你是否正在使用inAppBrowser插件。但我已经完成了在我的应用程序中完成的事情。

首先通过运行以下命令安装inAppBrowser插件:

离子cordova插件添加cordova-plugin-inappbrowser npm install @ ionic-native / in-app-browser

然后将inAppBrowser添加到app.module.ts文件的提供程序,如下所示:

app.module.ts

import { InAppBrowser } from '@ionic-native/in-app-browser';
...
...

@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    ...
    ...
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    ...
    ...
    InAppBrowser,
    ...
    ...
  ]
})
export class AppModule {}

然后你可以通过导入它在页面中使用inAppBrowser,所以先导入它:

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

然后将它注入构造函数:

constructor(public iab: InAppBrowser) {

}

现在你必须使用create()方法打开页面内的网页:

let browser = this.iab.create("...url...", '_blank',{
    location:'yes'
});

还有许多其他选项以及更多配置inappbrowser。

希望这会帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.