1

I have a cordova app and using InAppBrowser to login to a website. On Successful login, I need to pass the response to the App. I am using executeScript() to achieve and the same is working fine in Android, whereas in iOS, the callback for executeScript() is not getting fired.

My Load stop event listener is as follows

var ref = cordova.InAppBrowser.open("XXXX.html", "_blank", 'location=yes,toolbar=yes');


function iabLoadStop(event) {
    alert("EXECUTING SCRIPT")
    ref.executeScript({
        code: "document.body.innerHTML"
    }, function(values) {
        alert("SCRIPT EXECUTED")
        alert(values)
    });
}

I am getting "EXECUTING SCRIPT" alert successfully on load stop event, but the executeScript() which was support to alert "SCRIPT EXECUTED" and the innerHTML is not getting fired.

raghav
  • 285
  • 2
  • 12
  • You can also use JSONP to call iabLoadStop. These links help you do handle JSONP-responses on the [client](https://stackoverflow.com/a/6132828/2401386) and [server (php)](https://stackoverflow.com/a/6809069/2401386). – Blauharley Dec 17 '17 at 11:29
  • My issue is not on iabLoadStop is getting called. iabLoadStop was trigerred successfully, but the CB for executeScript() is not getting fired. – raghav Dec 17 '17 at 11:30
  • Can you provide the code within XXXX.html to show of how this CB is called, please. – Blauharley Dec 17 '17 at 11:32
  • The code inside XXXX.html is a JSON as text { success: true } which is getting successfully alerted in Android, but not getting fired in iOS. – raghav Dec 17 '17 at 11:34
  • Have you also tried to remove the first alert within iabLoadStop? As this function stops the programm-flow and might prevent executeScript to work correctly on iOS. – Blauharley Dec 17 '17 at 11:40
  • @Blauharley Looks like the first alert() was indeed the reason as it stopped execution of the further functions. Thanks for the heads up. – raghav Dec 17 '17 at 11:49
  • You are welcome! – Blauharley Dec 17 '17 at 11:56

1 Answers1

0

As it turned out the reason was with the first alert. This function stops the programm-flow but also caused the code within XXXX.html, that is executed by executeScript, to stop.

So it should be avoided to call such functions (alert/confirm etc.) between event loadstop and executeScript, at least on iOS. There are alternatives like console.log.

Blauharley
  • 4,186
  • 6
  • 28
  • 47