I have this code in a click event
let browser = new InAppBrowser('http://example.com/test', '_self');
browser.executeScript({code: "(function() { alert(123); })()"});
When i click the button, inAppBrowser opens the page, but the script doesn't run.
I closed the browser and then clicked the button again, now the script does run.
Why it's not running for the first time?
Add executeScript inside a InAppBrowser.addEventListener (loadstart, loadstop, loaderror) then it will run at the first time. I am using ionic 1 but I guess it will also work in ionic 2. I added a sample code below. (This is how it look like in ionic 1).
browser.addEventListener('loadstart', function(){
browser.executeScript({code: "(function() { alert(123); })()"});
})
It's not working in this way anymore. Try it!
browser.on('loadstop').subscribe(() => {
browser.executeScript({code: 'your_code'})
});
This is working for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With