Webview In Ionic 3

老子叫甜甜 提交于 2019-12-24 12:17:01

问题


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. :)


回答1:


In simpleway without installing any plugin u can use tag inside which define url of your's blog. e.g In home.ts :

    import { DomSanitizer } from '@angular/platform-browser';
    url: any;
    constructor(private sanitize: DomSanitizer){
    this.url = sanitize.bypassSecurityTrustResourceUrl("YOUR_URL");
    }

and in home.html :

<iframe  height="100%" width="100%" [src]="url" name="iframe_a"></iframe>

Try this.




回答2:


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


来源:https://stackoverflow.com/questions/47299642/webview-in-ionic-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!