首页 > 解决方案 > 如何使用 WebView 加载 Google Play 页面?

问题描述

我使用 Ionic 3。此代码适用于其他网站,但使用 Google Play 的 url 它不起作用。如何使用 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>

先感谢您。

标签: htmltypescriptionic-frameworkwebviewgoogle-play

解决方案


You won't be able to do this.

You are trying to load Google Play in a frame from a different domain name. If Google allowed this, it would be a big security risk, for example, it might let you trick the user into clicking on your site when they thought they were clicking on Play.

In order to prevent this, Google, and other sites use the "X-FRAME-OPTIONS" header set to "SAMEORIGIN". This tells the browser to not allow this to be put in an iframe unless the source URL also comes from play.google.com. Lots of other web pages do this too. You can see this if you open play.google.com in chrome, and use the developer tools to look at the header on the request.


推荐阅读