cordova android inAppBrowser inside inAppBrowser

3.2k views Asked by At

I open web page in my cordova app with

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

Is it possible to open links on this page with InAppBrowser _blank ?

Now I have an error

InAppBrowser does not support Cordova API calls

Thanks

2

There are 2 answers

2
Mohammed Imran N On

Alright, by default InAppBrowser plugin installs in Cordova app, so no need to add any explicit plugin..

use this code to open

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

Updated:

onclick="window.open('https://example.com','_blank','location=yes','closebuttoncaption=Return','EnableViewPortScale=no');"/>
  • _self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
  • _blank: Opens in the InAppBrowser.
  • _system: Opens in the system's web browser.

Options for the InAppBrowser. Optional, defaulting to: location=yes. (String)

The options string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive. All platforms support the value below:

  • location: Set to yes or no to turn the InAppBrowser's location bar on or off. Android only:

  • hidden: set to yes to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to no (default) to have the browser open and load normally.

  • clearcache: set to yes to have the browser's cookie cache cleared before the new window is opened
  • clearsessioncache: set to yes to have the session cookie cache cleared before the new window is opened
  • zoom: set to yes to show Android browser's zoom controls, set to no to hide them. Default value is yes.
  • hardwareback: set to yes to use the hardware back button to navigate backwards through the InAppBrowser's history. If there is no previous page, the InAppBrowser will close. The default value is yes, so you must set it to no if you want the back button to simply close the InAppBrowser.

More info on https://github.com/apache/cordova-plugin-inappbrowser

1
Kishan Bharda On

Use create() method instead of open(). I don't know you are using inAppBrowser plugin or not. But i have done following things to done right in my app.

First install inAppBrowser plugin by running following command :

ionic cordova plugin add cordova-plugin-inappbrowser npm install @ionic-native/in-app-browser

and then add inAppBrowser to app.module.ts file's provider as below :

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

then you can use inAppBrowser in your page by importing it so first import it :

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

then inject it to constructor :

constructor(public iab: InAppBrowser) {

}

Now you have to use create() method to open webpage inside the page :

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

There are many others options as well as for more configuration inappbrowser.

Hope this will help you.