deviceReady not working in PhoneGap application, how to?

后端 未结 13 1147
攒了一身酷
攒了一身酷 2020-12-06 09:52

I have a simple PhoneGap application as fallows:



    
        PhoneGap powered App
         


        
相关标签:
13条回答
  • 2020-12-06 10:38

    You're binding a handler to deviceready before you've defined the handler.

    Correct would be:

    function onDeviceReady(){
        alert('123')
    }
    
    document.addEventListener("deviceready", onDeviceReady, false);
    

    And obviously your phonegap-2.0.0.js file (or other version) should be included in the file before this point.

    0 讨论(0)
  • 2020-12-06 10:38

    Make sure below path is correct and both are need to be included into html :

            <script type="text/javascript"  src="cordova.js"></script>
            <script src="js/jquery-1.11.2.min.js"></script>
    
      <script type="text/javascript">
            $(document).ready(function(){
            document.addEventListener("deviceready", onDeviceReady, false);
            });
    
            function onDeviceReady() {
            alert("inside onDeviceReady");
            }
            </script>
    
    0 讨论(0)
  • 2020-12-06 10:38

    Biggest problem with PhoneGap examples are incorrect javascript syntax. Please be careful with this.. for this question,onDeviceReady should have braces...

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

    0 讨论(0)
  • 2020-12-06 10:39

    Add you event listener for deviceready inside you doc ready...

    <script type="text/javascript" charset="utf-8">
        $(document).ready(function () {
             document.addEventListener("deviceready", onDeviceReady, true); 
        });
    
        function onDeviceReady() {
            alert ('123');
        }
    </script>
    

    You dont want to call onDeviceReady() as this will run the function when you add the listener...

    0 讨论(0)
  • 2020-12-06 10:40

    When using PhoneGap 3.0 with WP8 Device Ready will not work because Phonegap.js is NOT INCLUDED in the Visual Studio solution.

    The solution is to include it manually for now.

    0 讨论(0)
  • 2020-12-06 10:40

    I'm see in your code one problem, in the method, you need add onDeviceReady() equals here:

    document.addEventListener("deviceready", onDeviceReady(), false);
    

    that worked for me!!

    0 讨论(0)
提交回复
热议问题