An app is using Cordova with InAppBrowser plugin version 3.2.1 to load a webpage built in Asp.Net 4.5.2. We have been experiencing erratic behaviour, so I've made a page to catch the problem and share it here.
This page contains a really simple button executing JS within the onclick event:
<button onclick="alert('1'); alert('2'); alert('3');"> EXECUTION</button>
It works perfectly, but when the website is embed in the app, the execution order runs backwards, displaying:
- Alert 3
- Alert 2
- Alert 1
Using unobstrusive JS with the same results:
<button id="testButton">Test</button>
$(document).ready(function () {
$("#testButton").click(function () {
alert('1');
alert('2');
alert('3');
});
});
Running the website in ios with Safari works perfectly fine.
Any idea?
Update
As suggested by @Bergi in the comments, adding a sleep timeout
verifies a problem managing synchronous calls. Following code triggers the alerts in the right order:
$("#testButton").click(function () {
alert('1');
setTimeout(function () { alert('2'); }, 2000);
setTimeout(function(){ alert('3'); }, 4000);
});
But not when the timeouts are closer. The following displays the alerts in wrong order:
$("#testButton").click(function () {
alert('1');
setTimeout(function () { alert('2'); }, 1);
setTimeout(function(){ alert('3'); }, 2);
});
Update 2
As proposed by @Bergi in the comments, I've tried:
$("#testButton").click(function () {
var x = []; x.push(1); x.push(2); alert(x);
});
With a correct result, displaying an alert containing: "1,2".
Issue has been reported.
alert
, rendering them all at once (on top of each other). You might verify this by trying to add somesleep()
calls in between. – Kendraalert()
:-) – Kendraalert()
is just to simplify the code and share it here. Of course that is not our code in production ;) – Raffinsleep()
or justconsole.log()
to verify. :) – Superaltarvar x = []; x.push(1); x.push(2); alert(x)
- does it throw an exception? Or alert2,1
? Or does it work as expected? – Kendraalert()
call. Does this browser support eitherconsole.log
ordebugger
statements? If not, you could putfetch
orXMLHttpRequest
calls in between to fetch some nonexistent resource on your server, e.g.fetch("log-one")
,fetch("log-two")
. The fetches will fail with 404 errors, but you can check the server log to see the order they arrived. I'll bet they all arrive in a row before you click on any of the alerts. – Caprice