如何使用WebView加载Google Play页面?

时间:2018-06-25 13:26:44

标签: html typescript ionic-framework webview google-play

我使用的是Ionic3。此代码可用于其他网站,但不能用于Google Play的网址。如何使用WebView加载Google Play页面?

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { InAppBrowser, InAppBrowserOptions } from '@ionic-native/in-app-browser';

declare var navigator: any;
declare var Connection: any;

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

export class HomePage {
    Connection: any;
    isLaunch: Boolean = false;

    constructor( private platform: Platform, private iab: InAppBrowser) {
        this.platform.ready().then(() => {
            this.launch();
        });

    }

    launch() {
        this.isLaunch = true;
        const browser = this.iab.create('https://play.google.com','_self' , "location=yes");

        browser.show();
    }
    }
 <ion-content>
    <iframe width='100%' height='100%'
    src="https://play.google.com/" frameborder="0" allowfullscreen>
   </iframe>
  </ion-content>

谢谢。

2 个答案:

答案 0 :(得分:0)

我使用in-app-browser模块将网页加载到应用程序中。 我编写了以下代码以在应用程序中显示网页。

  import {Component} from '@angular/core';
  import {NavController, Platform} from 'ionic-angular';
  import { InAppBrowser } from '@ionic-native/in-app-browser';

  declare var navigator: any;
  declare var Connection: any;

  @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
  })
  export class HomePage {
      Connection: any;
      isLaunch: Boolean = false;

      constructor( private platform: Platform, private iab: InAppBrowser) {
          this.platform.ready().then(() => {
              this.launch();
          });

      }

      launch() {
          this.isLaunch = true;
          const browser = this.iab.create('https://play.google.com','_self' , "location=yes");

          browser.show();
      }
  }

<ion-content>

  <div #frame style="width:100%;height:100%;overflow:scroll !important;-webkit-overflow-scrolling:touch !important"> 
    <iframe [src]="https://play.google.com" class="iframe" scrolling="yes" ></iframe> </div>
  
</ion-content>

答案 1 :(得分:0)

您将无法执行此操作。

您正在尝试从其他域名的框架中加载Google Play。如果Google允许这样做,那么这将带来很大的安全风险,例如,当用户认为他们点击了Play时,它可能会诱使用户点击您的网站。

为了防止这种情况,Google和其他站点使用设置为“ SAMEORIGIN”的“ X-FRAME-OPTIONS”标头。这告诉浏览器不允许将其放在iframe中,除非源URL也来自play.google.com。许多其他网页也这样做。如果您在chrome中打开play.google.com,并使用开发者工具查看请求的标头,就会看到此信息。