Context
I'm trying to simulate a WebView using Intel XDK. Before reading some post on Stack Overflow I read that the better way to archive this is using a window.location = "url";
. It worked like a charm.
Problem
Now I want to bind the hardware backbutton, so the user can confirm is he want or not to close the app. The problem is that it only works if the window.location
doesn't execute.
Code
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script src="cordova.js"></script>
<script>
window.location = "https://google.com";
var tried = false;
document.addEventListener("backbutton", backButton, false);
function backButton(){
if (tried){
navigator.app.exitApp();
}
else {
alert('TEST: Next time APP should close');
tried = !tried;
}
}
</script>
</head>
<body>
</body>
</html>
Results
Commenting window.location
Executing window.location
Thanks!