Webview In Ionic 3

Foram Sangani picture Foram Sangani · Nov 15, 2017 · Viewed 16.9k times · Source

I have my one blog which i want to convert into ionic app. I use InAppBrowser plugin but the problem is when i press the back button it will come to my default ionic home page.

i follow the below steps :

ionic start myblog

ionic platform add android

ionic cordova plugin add cordova-plugin-inappbrowser

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

and then added provider in app.module and in home.ts write the following.

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

constructor(private iab: InAppBrowser) { }


...


const browser = this.iab.create('https://ionicframework.com/','_self','location=no');
browser.show();

Also location=no is not working. Like android ionic provide the webview ?? can anyone help me out ? any help is appreciated. :)

Answer

Kishan Oza picture Kishan Oza · Nov 16, 2017

Simple and sort solution from the my github repo

in home.html

<iframe  height="100%" width="100%" [src]="urlpaste()"></iframe>

and in home.ts

import { Component } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  url: any;
  constructor(private sanitize: DomSanitizer) {}
  urlpaste(){
    this.url = "https://hackerrankgeek.wordpress.com/";
    return this.sanitize.bypassSecurityTrustResourceUrl(this.url);
  }
}