Call javascript when launch app with cordova app


(chans) #1

Hi everyone,
I used cordova and Hype to make app.
I used this code to show an alert when app launch, it worked but I got an another issue.
Click Home button(on device or simulator) and re-open app, this code did not run, no alert show.

  <script type="text/javascript" src="js/index.js"></script>

  <script type="text/javascript" charset="utf-8">

    document.addEventListener("deviceready", onDeviceReady, true);
    function onDeviceReady() {
        alert ('123');
    }
</script>

<!-- end copy -->

This code runs only one time ( first time ) when launch app.
How to call alert (‘123’) every time launch app.
Thank you so much.


(Hans-Gerd Claßen) #2

what happens if you remove the listener when function ‘onDeviceReady’ is called? just a guess …


(chans) #3

Sorry, What do you mean?


(Hans-Gerd Claßen) #4

well, just remove it when it has been called successfully …
https://www.w3schools.com/jsref/met_element_removeeventlistener.asp

or …


(chans) #5

You mean document.removeEventListener

Nothing change. alert only show one time when app launch first time and nothing show on next time