【问题标题】:How to load Google Play page with WebView?如何使用 WebView 加载 Google Play 页面?
【发布时间】:2018-12-04 02:19:35
【问题描述】:

我使用 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>

提前谢谢你。

【问题讨论】:

  • 您要加载应用安装页面吗?还是主站点?
  • 你似乎也在同时尝试 iframe 和 inAppBrowser...
  • 我要显示一个音乐专辑页面,例如:[link] (play.google.com/store/music/album/…)

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


【解决方案1】:

我使用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>

【讨论】:

  • 这很好,但是我的导航栏不见了,我只想在一页上玩谷歌,请问我该怎么办?我想要只喜欢这个页面的专辑页面,例如:[link] (play.google.com/store/music/album/…)
  • 那么 appbrowser 并没有完全为你使用,因为它会隐藏你的应用程序的导航栏和页脚。但你可以这样做&lt;ion-content&gt; &lt;div #frame style="width:100%;height:100%;overflow:scroll !important;-webkit-overflow-scrolling:touch !important"&gt; &lt;iframe [src]="adURL" class="iframe" scrolling="yes" &gt;&lt;/iframe&gt; &lt;/div&gt; &lt;/ion-content&gt;
  • 我在我的 .html 页面上添加了这个,但没有改变。仍然没有导航栏...我不明白..我应该怎么做? :s
【解决方案2】:

你不能这样做。

您正尝试从不同域名的框架中加载 Google Play。如果 Google 允许这样做,这将是一个很大的安全风险,例如,它可能会让您诱使用户在他们认为他们正在点击 Play 时点击您的网站。

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

【讨论】:

  • 我明白了。但是我能为这个问题做些什么呢?我不想分享整个网站,只想分享一个有音乐专辑的页面。
  • 你不能。您唯一的选择是在浏览器中重定向到它。
  • 我明白你想要什么。这是不可能的。
猜你喜欢
  • 2015-02-25
  • 2012-05-02
  • 2015-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多