Not able to attach event handler in Ionic 2 on InAppBrowser

百般思念 提交于 2019-12-11 09:26:52

问题


I'm very new to Ionic 2 framework and I'm trying to write an app in which I need to open an external URL in an embedded browser (InAppBrowser). I create an InAppBrowser instance and launch the browser. The browser opens and it also opens the link, but I keep getting an error.

Cannot read property 'addEventListener' of undefined

Here's the code that I'm using:

let browser = new InAppBrowser(
    "http://www.google.com",
    "_blank",
    "location=no,hidden=yes",
);
console.log(browser);
browser.on('loadstop').subscribe(
    (res) => {
        // Handle url checking and body parsing here
    },
    (error) => {
        // Handle error here
    }
);
browser.on('deviceready').subscribe(
    (res) => {
        browser.show();
        console.log(res);
    },
    (error) => {
        console.log(error);
    }
);

I don't understand what I'm doing wrong. I want to check what the url is everytime the browser loads a webpage and if it is the desired web page then parse the body of the browser and then close it.

I'm trying to integrate a payment gateway. So basically I load the payment url in the browser, user makes the payment and the payment gateway redirects the user to my backend url. Now I want to parse what my backend returns and close the browser. Also, that console.log(browser) in there does logs an instance of InAppBrowser.

来源:https://stackoverflow.com/questions/42114950/not-able-to-attach-event-handler-in-ionic-2-on-inappbrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!