【问题标题】:Ionic 5 Angular Running In App Browser .executeScript() not workingIonic 5 Angular 在应用程序浏览器中运行 .executeScript() 不起作用
【发布时间】:2020-05-17 01:33:24
【问题描述】:

我正在尝试在 ionic 中打开一个 Spotify 身份验证 URL。我正在使用应用内浏览器将用户重定向到那里然后返回。 (Iab 是 InappBrowser,this.url 是一个工作 url,仅供参考)。这是我当前的代码:

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: Cannot read property 'subscribe' of undefined”。并且没有显示警报。

【问题讨论】:

    标签: javascript angular ionic-framework inappbrowser


    【解决方案1】:

    在 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");
          `
        })
    })
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-06-19
      • 2020-03-01
      • 2011-10-26
      • 2015-05-29
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多