问题
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