【问题标题】:Webview In Ionic 3Ionic 3 中的 Web 视图
【发布时间】:2019-10-20 16:13:01
【问题描述】:

我有一个博客,我想将其转换为 ionic 应用程序。 我使用InAppBrowser 插件,但问题是当我按下后退按钮时,它会进入我的默认离子home 页面。

我遵循以下步骤:

ionic start myblog

ionic platform add android

ionic cordova plugin add cordova-plugin-inappbrowser

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

然后在app.modulehome.ts 中添加provider,写下以下内容。

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

location=no 也不起作用。 像android ionic 提供webview ?? 谁能帮我吗 ? 任何帮助表示赞赏。 :)

【问题讨论】:

    标签: cordova ionic-framework inappbrowser ionic-webview


    【解决方案1】:

    来自my github repo的简单排序解决方案

    home.html

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

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

    【讨论】:

      【解决方案2】:

      在不安装任何插件的情况下,您可以使用标签来定义您博客的网址。 例如在 home.ts 中:

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

      home.html

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

      试试这个。

      【讨论】:

      • 告诉 url 不安全
      • 你可以使用 DOMSanititizer 吗?
      • 是的,我像你说的那样使用
      猜你喜欢
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 2018-04-22
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 2015-06-12
      • 2019-02-21
      相关资源
      最近更新 更多