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.