在应用程序浏览器中运行的离子5角.executeScript()不起作用

问题描述 投票:0回答:1

我正在尝试在ionic中打开Spotify身份验证URL。我正在使用应用程序内浏览器将用户重定向到该位置,然后返回。 (Iab是InappBrowser,this.url是有效的网址FYI)。这是我当前的代码:

const browser = this.Iab.create(this.url,"_blank",'location=yes')
    browser.on('loadstop').subscribe(function(){
      browser.executeScript({code:'alert("hello world")'}).then((cookie) =>{
      console.log(cookie)
    })
})

我收到错误:我的应用上出现“ ERROR TypeError:无法读取未定义的属性'subscribe'”。而且警报未显示。

javascript angular ionic-framework inappbrowser
1个回答
0
投票

不会从iab中显示警报(对于IAB的最新版本,此提示至少在iOS上显示)。因此,请使用console.log满足您的调试需求。以下是有效的方法:

 this.browser = this.iab.create(url,"_blank","hidden=yes,toolbar=no");
 this.browser.on('loadstop').subscribe(event => {
    console.log("load stop", event)
    this.browser.show();

    this.browser.executeScript({
      code: ` //alert will not work here 
            console.log("HELLO");
      `
    })
})

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.