I'm making an Android application with Apache Cordova. Everything works on Android 6.0, which is using Chrome by default, the problem is on Android 4.2.2 (Samsung Galaxy S4 mini) which is using the default Android browser.
If i'm not mistaken, then the application is "started" in the default Android browser after it's compiled with cordova and installed on the Android operating system.
In the default Android browser the page is empty on load. But in Chrome everything works fine.
The problem is in the default Android 4.2.2 browser. It's not working in the default browser for Nokia 1520 (which is using the Windows Phone OS).
index.html:
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery-3.1.1.min.js" type="text/javascript"></script>
<script src="2.js" type="text/javascript"></script>
<script src="1.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
</div>
</body>
</html>
1.js:
$(document).ready(function() {
$('#content').html("<span>test3</span>"); // Works fine (i can see test3 on the page).
showLogin();
});
2.js (nothing inside this file works, i can't see test1 nor test2 on the page):
$('#content').html("<span>test1</span>");
function showLogin() {
$('#content').html(`<span>
test2
</span>`);
}
WHAT I TRIED #1
I also tried to call the showLogin()
inside setTimeout()
:
setTimeout(function() {
showLogin();
}, 1000);
WHAT I TRIED #2
1.js:
$(document).ready(function() {
$('#content').html("<span>test3</span>"); // Works fine.
showLogin();
});
2.js (nothing inside this file works):
$(document).ready(function() {
$('#content').html("<span>test1</span>");
function showLogin() {
$('#content').html(`<span>
test2
</span>`);
}
});
The problem was caused by the quotes for the multiline JavaScript string "`".
After i changed this:
To this:
everything worked just fine.
It looks like that these quotes are not supported in the stock Android browser. I guess that this triggered an exception in the 2.js file and that was the reason that the other code in 2.js didn't execute.
I ended up using the backslashes for the multiline strings like this:
The backslash also works inside single quotes, like this: