Bind Intel XDK stand, even before redirection

Context

I am trying to simulate a WebView using the Intel XDK. Before reading the stack overflow message, I read that the best way to archive is to use window.location = "url";. It worked like a charm.

Problem

Now I want to bind the hardware stand so that the user can confirm whether he wants or does not close the application. The problem is that it only works if window.locationit is not executed.

the 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

enter image description here

Performance window.location

enter image description here

Thank!

+4
source share
1 answer

Each page has its own javascript, if you switch the page, all javascript will be lost.

, , , using location.href, cordova.js.

, , , google.

, , , java- cordova, , ​​ , Java- cordova "" , :

KeyEvent.KEYCODE_BACK ,

+1

Source: https://habr.com/ru/post/1657350/


All Articles